Skip to content

Commit 50e261a

Browse files
Merge pull request #21 from alexandrefassio/master
Merge to V0.8.0
2 parents 5aa7b3c + a020b2d commit 50e261a

28 files changed

+33732
-1728
lines changed

.gitignore

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,44 @@
1-
# Todos os arquivos:
2-
1+
# Files in the format:
32
*.htaccess
43
*.dat
54
*.bak
65
*.log
6+
*.pdb
7+
8+
*.output
79

8-
test*.py
10+
*.csv
11+
12+
*\.fuse_hidden*
913

1014
.project
1115
.pydevproject
1216

13-
14-
# Todos arquivos dos diretórios:
17+
# Remove entire directories:
1518

1619
tmp/
1720
www/system
1821
www/application/config
1922
www/data
2023
__pycache__
21-
scripts/output
22-
23-
*.pdb
24-
25-
*.output
26-
27-
*.csv
2824

29-
scripts/compare_molecules\.py
30-
31-
scripts/molecules_with_error\.py
32-
33-
scripts/obsolete/
34-
35-
scripts/connect_to_server\.sh
36-
37-
scripts/napoli\.log*
38-
39-
*\.fuse_hidden*
40-
scripts/classify_atom_groups\.py
4125

4226
# temporary files (e.g. Vim)
4327
*~
4428
*.swp
4529
*.swo
4630

31+
4732
# Byte-compiled / optimized / DLL files
4833
__pycache__/
4934
*.py[cod]
5035
*$py.class
5136

37+
5238
# C extensions
5339
*.so
5440

41+
5542
# Distribution / packaging
5643
.Python
5744
build/
@@ -73,21 +60,25 @@ share/python-wheels/
7360
*.egg
7461
MANIFEST
7562

63+
7664
# Sphinx documentation
7765
docs/_build/
7866

67+
7968
# Jupyter Notebook
8069
.ipynb_checkpoints
8170

71+
8272
# IPython
8373
profile_default/
8474
ipython_config.py
8575

76+
8677
# Environments
8778
.env
8879
.venv
8980
env/
9081
venv/
9182
ENV/
9283
env.bak/
93-
venv.bak/
84+
venv.bak/

luna/MyBio/util.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from openbabel.pybel import readfile
1010
from openbabel.pybel import Molecule as PybelWrapper
1111

12-
from rdkit.Chem import MolFromMolBlock, MolFromMolFile, SanitizeFlags, SanitizeMol
12+
from rdkit.Chem import MolFromMolBlock, MolFromMolFile, SanitizeFlags, SanitizeMol, MolToMolFile
1313

1414
from luna.util.file import is_directory_valid, get_unique_filename, remove_files
1515
from luna.util.default_values import ENTRY_SEPARATOR, OPENBABEL
@@ -23,6 +23,9 @@
2323
from luna.mol.standardiser import ResiduesStandardiser
2424
from luna.mol.wrappers.base import MolWrapper
2525
from luna.mol.wrappers.obabel import convert_molecule
26+
from luna.mol.wrappers.rdkit import read_mol_from_file
27+
28+
from luna.mol.templates import LigandExpoTemplate
2629

2730
from luna.util.exceptions import (IllegalArgumentError, MoleculeNotFoundError, ChainNotFoundError,
2831
FileNotCreated, PDBNotReadError, MoleculeSizeError, MoleculeObjectError)
@@ -295,8 +298,9 @@ def get_residue_neighbors(residue, select=Select()):
295298

296299

297300
def biopython_entity_to_mol(entity, select=Select(), validate_mol=True, standardize_mol=True,
298-
add_h=False, ph=None, break_metal_bonds=False, mol_obj_type="rdkit", openbabel=OPENBABEL,
299-
tmp_path=None, keep_tmp_files=False):
301+
template=None, add_h=False, ph=None,
302+
break_metal_bonds=False, mol_obj_type="rdkit", wrapped=True,
303+
openbabel=OPENBABEL, tmp_path=None, keep_tmp_files=False):
300304

301305
tmp_path = tmp_path or tempfile.gettempdir()
302306

@@ -312,10 +316,24 @@ def biopython_entity_to_mol(entity, select=Select(), validate_mol=True, standard
312316

313317
logger.debug("First: try to create a new PDB file (%s) from the provided entity." % pdb_file)
314318
# Apparently, Open Babel creates a bug when it tries to parse a file with CONECTS containing serial numbers with more than 4 digits.
315-
# E.g.: 1OZH:A:HE3:1406, line CONECT162811627916282.
316-
# By setting preserve_atom_numbering to False, it seems the problem is solved.
319+
# E.g.: 1OZH:A:HE3:1406, line CONECT162811627916282. By setting preserve_atom_numbering to False, it solves the problem.
317320
save_to_file(entity, pdb_file, select, preserve_atom_numbering=False)
318321

322+
ini_input_file = pdb_file
323+
if template is not None:
324+
if entity.level == "R" and entity.is_hetatm():
325+
# Note that the template molecule should have no explicit hydrogens else the algorithm will fail.
326+
rdmol = read_mol_from_file(pdb_file, mol_format="pdb", removeHs=True)
327+
new_rdmol = template.assign_bond_order(rdmol, entity.resname)
328+
329+
ini_input_file = '%s_tmp-mol-file.mol' % filename
330+
MolToMolFile(new_rdmol, ini_input_file)
331+
332+
if not keep_tmp_files:
333+
remove_files([pdb_file])
334+
else:
335+
logger.warning("It cannot apply a template on the provided entity because it should be a single compound (Residue class).")
336+
319337
# Convert the PDB file to Mol file with the proper protonation and hydrogen addition if required.
320338
mol_file = '%s_mol-file.mol' % filename
321339
ob_opt = {"error-level": 5}
@@ -326,7 +344,7 @@ def biopython_entity_to_mol(entity, select=Select(), validate_mol=True, standard
326344
ob_opt["p"] = ph
327345
else:
328346
ob_opt["h"] = ""
329-
convert_molecule(pdb_file, mol_file, opt=ob_opt, openbabel=openbabel)
347+
convert_molecule(ini_input_file, mol_file, opt=ob_opt, openbabel=openbabel)
330348

331349
# Currently, ignored atoms are only metals.
332350
ignored_atoms = []
@@ -429,6 +447,9 @@ def biopython_entity_to_mol(entity, select=Select(), validate_mol=True, standard
429447

430448
# Remove temporary files.
431449
if not keep_tmp_files:
432-
remove_files([pdb_file, mol_file])
450+
remove_files([ini_input_file, mol_file])
451+
452+
if wrapped:
453+
mol_obj = MolWrapper(mol_obj)
433454

434455
return mol_obj, ignored_atoms

0 commit comments

Comments
 (0)