| Total Complexity | 9 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | #! /usr/bin/env python |
||
| 12 | class MOEDescriptorCalculator(object): |
||
|
|
|||
| 13 | |||
| 14 | |||
| 15 | def __init__(self): |
||
| 16 | pass |
||
| 17 | |||
| 18 | def transform(self, obj): |
||
| 19 | if isinstance(obj, core.Mol): |
||
| 20 | return self._transform_series(pd.Series(obj)).iloc[0] |
||
| 21 | elif isinstance(obj, pd.Series): |
||
| 22 | return self._transform_series(obj) |
||
| 23 | elif isinstance(obj, pd.DataFrame): |
||
| 24 | return self._transform_series(obj.structure) |
||
| 25 | elif isinstance(obj, (tuple, list)): |
||
| 26 | return self._transform_series(obj) |
||
| 27 | else: |
||
| 28 | raise NotImplementedError |
||
| 29 | |||
| 30 | def _transform_series(self, series): |
||
| 31 | |||
| 32 | with tempfile.NamedTemporaryFile(suffix='.sdf') as in_file, tempfile.NamedTemporaryFile() as out_file: |
||
| 33 | # write mols to file |
||
| 34 | write_sdf(series, in_file.name) |
||
| 35 | args = ['mddesc', in_file.name, '-o', out_file.name] + self.index |
||
| 36 | |||
| 37 | LOGGER.info('Running: ' + ' '.join(args)) |
||
| 38 | |||
| 39 | # call command line |
||
| 40 | subprocess.call(args) |
||
| 41 | try: |
||
| 42 | finished = pd.read_table(out_file.name).set_index('id') |
||
| 43 | except Exception: |
||
| 44 | finished = None |
||
| 45 | finished.index = series.index |
||
| 46 | return finished |
||
| 47 | |||
| 49 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.