ForceField   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 17.5%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 15
c 2
b 0
f 2
dl 0
loc 67
ccs 7
cts 40
cp 0.175
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
B embed() 0 15 5
A columns() 0 3 1
A __init__() 0 8 1
A _optimize() 0 3 1
C _transform_mol() 0 23 7
1
#! /usr/bin/env python
2
#
3
# Copyright (C) 2016 Rich Lewis <[email protected]>
4
# License: 3-clause BSD
5
6 1
"""
7
## skchem.forcefields.base
8
9
Module specifying base class for forcefields.
10
"""
11 1
import warnings
12 1
from abc import ABCMeta, abstractmethod
13
14 1
import pandas as pd
0 ignored issues
show
Configuration introduced by
The import pandas could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
15 1
from rdkit.Chem.rdDistGeom import EmbedMolecule
0 ignored issues
show
Configuration introduced by
The import rdkit.Chem.rdDistGeom could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
16
17 1
from ..utils import Suppressor
18 1
from ..base import Transformer
19 1
from ..filters.base import TransformFilter
20
21
22 1
class ForceField(Transformer, TransformFilter):
23
    # TODO: Multiple conformer generation handling.
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
24
25
    """ Base forcefield class.
26
27
    Filter drops those that fail to be optimized.
28
29
     """
30
31 1
    __metaclass__ = ABCMeta
32
33 1
    def __init__(self, preembed=True, warn_on_fail=True, error_on_fail=False,
0 ignored issues
show
best-practice introduced by
Too many arguments (7/5)
Loading history...
34
                 add_hs=True, n_jobs=1, verbose=True):
35
36
        self.add_hs = add_hs
37
        self.warn_on_fail = warn_on_fail
38
        self.error_on_fail = error_on_fail
39
        self.preembed = preembed
40
        super(ForceField, self).__init__(verbose=verbose, n_jobs=n_jobs)
41
42 1
    @property
43
    def columns(self):
44
        return pd.Index(['structure'])
45
46 1
    def embed(self, mol):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
47
48
        success = EmbedMolecule(mol)
49
        if success == -1:
50
            msg = 'Failed to Embed Molecule {}'.format(mol.name)
51
            if self.error_on_fail:
52
                raise RuntimeError(msg)
53
            elif self.warn_on_fail:
54
                warnings.warn(msg)
55
            return None
56
57
        if self.add_hs:
58
            return mol.add_hs(add_coords=True)
59
        else:
60
            return mol
61
62 1
    def _transform_mol(self, mol):
63
64
        mol = mol.copy()
65
66
        with Suppressor():
67
            if self.preembed:
68
                mol = self.embed(mol)
69
70
            if mol is None:  # embedding failed
71
                return None
72
73
            res = self._optimize(mol)
74
75
        if res == -1:
76
            msg = 'Failed to optimize molecule \'{}\' using {}'.format(
77
                mol.name, self.__class__)
78
            if self.error_on_fail:
79
                raise RuntimeError(msg)
80
            elif self.warn_on_fail:
81
                warnings.warn(msg)
82
            return None
83
84
        return mol
85
86 1
    @abstractmethod
87
    def _optimize(self, mol):
88
        pass
89
90
91 1
class RoughEmbedding(ForceField):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
92 1
    def _optimize(self, mol):
93
        return mol
94