Total Complexity | 9 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Coverage | 16% |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
1 | #! /usr/bin/env python |
||
12 | 1 | class MOEDescriptorCalculator(object): |
|
|
|||
13 | |||
14 | 1 | def __init__(self): |
|
15 | pass |
||
16 | |||
17 | 1 | def transform(self, obj): |
|
18 | if isinstance(obj, core.Mol): |
||
19 | return self._transform_series(pd.Series(obj)).iloc[0] |
||
20 | elif isinstance(obj, pd.Series): |
||
21 | return self._transform_series(obj) |
||
22 | elif isinstance(obj, pd.DataFrame): |
||
23 | return self._transform_series(obj.structure) |
||
24 | elif isinstance(obj, (tuple, list)): |
||
25 | return self._transform_series(obj) |
||
26 | else: |
||
27 | raise NotImplementedError |
||
28 | |||
29 | 1 | def _transform_series(self, series): |
|
30 | |||
31 | with tempfile.NamedTemporaryFile(suffix='.sdf') as in_file, tempfile.NamedTemporaryFile() as out_file: |
||
32 | # write mols to file |
||
33 | write_sdf(series, in_file.name) |
||
34 | args = ['mddesc', in_file.name, '-o', out_file.name] + self.index |
||
35 | |||
36 | LOGGER.info('Running: ' + ' '.join(args)) |
||
37 | |||
38 | # call command line |
||
39 | subprocess.call(args) |
||
40 | try: |
||
41 | finished = pd.read_table(out_file.name).set_index('id') |
||
42 | except Exception: |
||
43 | finished = None |
||
44 | finished.index = series.index |
||
45 | return finished |
||
46 | |||
48 |
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.