Révision 5c70d6c6
b/modules/isolated.py | ||
---|---|---|
1 | 1 |
"""Functions to generate the conformers to be adsorbed and the most stable one. |
2 | 2 |
|
3 |
functions. |
|
3 |
functions: |
|
4 |
remove_C_linked_Hs: Removes hydrogens bonded to a carbon atom from a molecule. |
|
4 | 5 |
gen_confs: Generate a number of different conformers in random orientations. |
5 | 6 |
run_isolated: directs the execution of functions to achieve the goal |
6 | 7 |
""" |
... | ... | |
11 | 12 |
logger = logging.getLogger('DockOnSurf') |
12 | 13 |
|
13 | 14 |
|
15 |
def remove_C_linked_Hs(mol): |
|
16 |
"""Removes hydrogens bonded to a carbon atom from a rdkit mol object. |
|
17 |
|
|
18 |
@param mol: rdkit mol object of the molecule with hydrogens |
|
19 |
@return: rdkit mol object of the molecule without hydrogens linked to carbon |
|
20 |
atoms. |
|
21 |
The functions removes the hydrogens bonded to C atoms while keeping the |
|
22 |
ones bonded to heteroatoms. |
|
23 |
""" |
|
24 |
from rdkit import Chem |
|
25 |
|
|
26 |
mol = Chem.RWMol(mol) |
|
27 |
rev_atm_idxs = [atom.GetIdx() for atom in reversed(mol.GetAtoms())] |
|
28 |
|
|
29 |
for atm_idx in rev_atm_idxs: |
|
30 |
atom = mol.GetAtomWithIdx(atm_idx) |
|
31 |
if atom.GetAtomicNum() != 1: |
|
32 |
continue |
|
33 |
for neigh in atom.GetNeighbors(): |
|
34 |
if neigh.GetAtomicNum() == 6: |
|
35 |
mol.RemoveAtom(atom.GetIdx()) |
|
36 |
return mol |
|
37 |
|
|
38 |
|
|
14 | 39 |
def gen_confs(mol, num_confs, rms_thld): |
15 | 40 |
"""Generate a number of different conformers in random orientations. |
16 | 41 |
|
... | ... | |
21 | 46 |
""" |
22 | 47 |
from rdkit.Chem import AllChem as Chem |
23 | 48 |
logger.info('Generating Conformers') |
24 |
conf_ids = Chem.EmbedMultipleConfs(mol, numConfs=num_confs, |
|
25 |
numThreads=0) |
|
49 |
conf_ids = Chem.EmbedMultipleConfs(mol, numConfs=num_confs, numThreads=0) |
|
26 | 50 |
for conf in conf_ids: |
27 |
Chem.UFFOptimizeMolecule(mol, confId=conf) # TODO: Do we want this? |
|
28 |
for conf1 in conf_ids: # TODO parallelize |
|
29 |
for conf2 in conf_ids[conf1+1:]: |
|
51 |
Chem.UFFOptimizeMolecule(mol, confId=conf) # TODO: Do we want this? |
|
52 |
|
|
53 |
Chem.AlignMolConformers(mol) |
|
54 |
mol_wo_Hs = remove_C_linked_Hs(mol) |
|
55 |
for conf1 in conf_ids: |
|
56 |
for conf2 in conf_ids[conf1 + 1:]: |
|
30 | 57 |
try: |
31 |
rms = Chem.GetConformerRMS(mol, conf1, conf2) |
|
58 |
rms = Chem.GetBestRMS(mol_wo_Hs, mol_wo_Hs, prbId=conf2, |
|
59 |
refId=conf1) |
|
32 | 60 |
except ValueError: |
33 | 61 |
continue |
34 | 62 |
else: |
35 | 63 |
if rms <= rms_thld: |
36 | 64 |
mol.RemoveConformer(conf2) |
37 | 65 |
|
38 |
logger.info(f'Generated {len(mol)} different conformers') |
|
39 |
return mol # TODO: mol indices |
|
66 |
for i, conf in enumerate(mol.GetConformers()): |
|
67 |
conf.SetId(i) |
|
68 |
|
|
69 |
logger.info(f'Generated {len(mol.GetConformers())} different conformers') |
|
70 |
return mol |
|
40 | 71 |
|
41 | 72 |
|
42 | 73 |
def run_isolated(inp_vars): |
Formats disponibles : Unified diff