Révision f3004731 modules/formats.py
b/modules/formats.py | ||
---|---|---|
1 | 1 |
"""Module for the conversion of coordinate files to library-workable objects |
2 | 2 |
|
3 | 3 |
functions: |
4 |
confs_to_mol_list: Converts the conformers inside a rdkit mol object to a list |
|
5 |
of separate mol objects. |
|
6 |
rdkit_mol_to_ase_atoms: Converts a rdkit mol object into ase Atoms object. |
|
4 | 7 |
adapt_format: Converts the coordinate files into a required library object type |
5 | 8 |
""" |
6 | 9 |
|
7 | 10 |
import logging |
11 |
|
|
12 |
import rdkit.Chem.AllChem as Chem |
|
13 |
|
|
8 | 14 |
logger = logging.getLogger('DockOnSurf') |
9 | 15 |
|
10 | 16 |
|
17 |
def confs_to_mol_list(mol: Chem.rdchem.Mol, idx_lst=None): |
|
18 |
"""Converts the conformers inside a rdkit mol object to a list of |
|
19 |
separate mol objects. |
|
20 |
|
|
21 |
@param mol: rdkit mol object containing at least one conformer. |
|
22 |
@param idx_lst: |
|
23 |
@return: list of separate mol objects. |
|
24 |
""" |
|
25 |
if idx_lst is None: |
|
26 |
idx_lst = list(range(mol.GetNumConformers())) |
|
27 |
return [Chem.MolFromMolBlock(Chem.MolToMolBlock(mol, confId=int(idx)), |
|
28 |
removeHs=False) for idx in idx_lst] |
|
29 |
|
|
30 |
|
|
31 |
def rdkit_mol_to_ase_atoms(mol: Chem.rdchem.Mol): |
|
32 |
"""Converts a rdkit mol object into ase Atoms object. |
|
33 |
@param mol: rdkit mol object containing only one conformer. |
|
34 |
@return ase.Atoms: ase Atoms object with the same coordinates. |
|
35 |
""" |
|
36 |
from ase import Atoms |
|
37 |
symbols = [atm.GetSymbol() for atm in mol.GetAtoms()] |
|
38 |
positions = mol.GetConformer(0).GetPositions() |
|
39 |
return Atoms(symbols=symbols, positions=positions) |
|
40 |
|
|
41 |
|
|
11 | 42 |
def adapt_format(requirement, coord_file): |
12 | 43 |
"""Converts the coordinate files into a required library object type. |
13 | 44 |
|
... | ... | |
27 | 58 |
f" has not yet been implemented" |
28 | 59 |
conv_info = f"Converted {coord_file} to {requirement} object type" |
29 | 60 |
|
30 |
fil_type_err = f'The {filetype( coord_file )} file formnat is not supported'
|
|
61 |
fil_type_err = f'The {filetype(coord_file)} file formnat is not supported'
|
|
31 | 62 |
|
32 | 63 |
if requirement not in req_vals: |
33 | 64 |
logger.error(lib_err) |
Formats disponibles : Unified diff