| Conditions | 7 |
| Total Lines | 77 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | #! /usr/bin/env python |
||
| 118 | def n_atoms(mol, above=None, below=None, include_hydrogens=False): |
||
| 119 | |||
| 120 | """ Whether the number of atoms in a molecule falls in a defined interval. |
||
| 121 | |||
| 122 | ``above <= n_atoms < below`` |
||
| 123 | |||
| 124 | Args: |
||
| 125 | mol: (skchem.Mol): |
||
| 126 | The molecule to be tested. |
||
| 127 | above (int): |
||
| 128 | The lower threshold number of atoms (exclusive). |
||
| 129 | Defaults to None. |
||
| 130 | below (int): |
||
| 131 | The higher threshold number of atoms (inclusive). |
||
| 132 | Defaults to None. |
||
| 133 | |||
| 134 | Returns: |
||
| 135 | bool: |
||
| 136 | Whether the molecule has more atoms than the threshold. |
||
| 137 | |||
| 138 | Examples: |
||
| 139 | |||
| 140 | Basic usage as a function on molecules: |
||
| 141 | |||
| 142 | >>> import skchem |
||
| 143 | >>> m = skchem.Mol.from_smiles('c1ccccc1') # benzene has 6 atoms. |
||
| 144 | |||
| 145 | |||
| 146 | Lower threshold: |
||
| 147 | |||
| 148 | >>> skchem.filters.n_atoms(m, above=3) |
||
| 149 | True |
||
| 150 | >>> skchem.filters.n_atoms(m, above=8) |
||
| 151 | False |
||
| 152 | |||
| 153 | Higher threshold: |
||
| 154 | |||
| 155 | >>> skchem.filters.n_atoms(m, below=8) |
||
| 156 | True |
||
| 157 | >>> skchem.filters.n_atoms(m, below=3) |
||
| 158 | False |
||
| 159 | |||
| 160 | Bounds work like Python slices - inclusive lower, exclusive upper: |
||
| 161 | |||
| 162 | >>> skchem.filters.n_atoms(m, above=6) |
||
| 163 | True |
||
| 164 | >>> skchem.filters.n_atoms(m, below=6) |
||
| 165 | False |
||
| 166 | |||
| 167 | Both can be used at once: |
||
| 168 | |||
| 169 | >>> skchem.filters.n_atoms(m, above=3, below=8) |
||
| 170 | True |
||
| 171 | |||
| 172 | More useful in combination with pandas data frames: |
||
| 173 | |||
| 174 | >>> import gzip |
||
| 175 | >>> sdf = gzip.open(skchem.data.resource('ames_mutagenicity.sdf.gz')) |
||
| 176 | >>> data = skchem.read_sdf(sdf) |
||
| 177 | >>> data.structure.apply(skchem.filters.n_atoms, above=5, below=50).value_counts() |
||
| 178 | True 4113 |
||
| 179 | False 223 |
||
| 180 | Name: structure, dtype: int64 |
||
| 181 | |||
| 182 | """ |
||
| 183 | if not above: |
||
| 184 | above = 0 |
||
| 185 | if not below: |
||
| 186 | below = 1000000 # arbitrarily large number |
||
| 187 | |||
| 188 | if not include_hydrogens: |
||
| 189 | n_a = len([a for a in mol.atoms if a.element is not 'H']) |
||
| 190 | else: |
||
| 191 | n_a = len(mol.atoms) |
||
| 192 | |||
| 193 | assert above < below, 'Interval {} < a < {} undefined.'.format(above, below) |
||
| 194 | return above <= n_a < below |
||
| 195 | |||
| 250 |
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.
2. Missing __init__.py files
This error could also result from missing
__init__.pyfiles in your module folders. Make sure that you place one file in each sub-folder.