dockonsurf / modules / isolated.py @ 5c70d6c6
Historique | Voir | Annoter | Télécharger (2,77 ko)
1 |
"""Functions to generate the conformers to be adsorbed and the most stable one.
|
---|---|
2 |
|
3 |
functions:
|
4 |
remove_C_linked_Hs: Removes hydrogens bonded to a carbon atom from a molecule.
|
5 |
gen_confs: Generate a number of different conformers in random orientations.
|
6 |
run_isolated: directs the execution of functions to achieve the goal
|
7 |
"""
|
8 |
import logging |
9 |
|
10 |
from formats import adapt_format |
11 |
|
12 |
logger = logging.getLogger('DockOnSurf')
|
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 |
|
39 |
def gen_confs(mol, num_confs, rms_thld): |
40 |
"""Generate a number of different conformers in random orientations.
|
41 |
|
42 |
@param mol: rdkit mol object of the molecule to be adsorbed.
|
43 |
@param num_confs: number of raw conformers to randomly generate.
|
44 |
@param rms_thld: rms threshold to consider two conformers as different.
|
45 |
@return: mol: rdkit mol object containing the different conformers.
|
46 |
"""
|
47 |
from rdkit.Chem import AllChem as Chem |
48 |
logger.info('Generating Conformers')
|
49 |
conf_ids = Chem.EmbedMultipleConfs(mol, numConfs=num_confs, numThreads=0)
|
50 |
for conf in conf_ids: |
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:]: |
57 |
try:
|
58 |
rms = Chem.GetBestRMS(mol_wo_Hs, mol_wo_Hs, prbId=conf2, |
59 |
refId=conf1) |
60 |
except ValueError: |
61 |
continue
|
62 |
else:
|
63 |
if rms <= rms_thld:
|
64 |
mol.RemoveConformer(conf2) |
65 |
|
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
|
71 |
|
72 |
|
73 |
def run_isolated(inp_vars): |
74 |
"""Directs the execution of functions to obtain the conformers to adsorb
|
75 |
|
76 |
@param inp_vars:
|
77 |
@return:
|
78 |
"""
|
79 |
logger.info('Carrying out procedures for the isolated molecule')
|
80 |
rd_mol = adapt_format('rdkit', inp_vars['molec_file']) |
81 |
confs = gen_confs(rd_mol, inp_vars['num_conformers'], inp_vars['iso_rms']) |