-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -571,6 +571,36 @@ def _initialize(self): | |
from peleffy.forcefield.parameters import BaseParameterWrapper | ||
self._parameters = BaseParameterWrapper() | ||
|
||
def _PDB_checkup(self, path): | ||
""" | ||
Safety check for PDB files in order to properly handle exceptions | ||
related with its format prior running the parameterization. | ||
Parameters | ||
---------- | ||
path : str | ||
The path to a PDB with the molecule structure | ||
""" | ||
# Parse PDB file | ||
atom_id, res_name, res_id = ([] for i in range(3)) | ||
for line in open(path): | ||
if not len(line.strip()) == 0: | ||
list = line.split() | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
martimunicoy
Owner
|
||
id = list[0] | ||
if id == 'HETATM': | ||
This comment has been minimized.
Sorry, something went wrong. |
||
atom_id.append(list[2]) | ||
res_name.append(list[3]) | ||
res_id.append(list[4]) | ||
|
||
# Handle exceptions related with the PDB file format | ||
assert res_id[:-1] == res_id[1:], \ | ||
This comment has been minimized.
Sorry, something went wrong.
martimunicoy
Owner
|
||
'A single ligand with immutable residue ids is expected' | ||
assert res_name[:-1] == res_name[1:], \ | ||
'A single ligand with immutable residue names is expected' | ||
assert len(atom_id) == len(set(atom_id)), \ | ||
'Ligand in input PDB has no unique atom names' | ||
|
||
|
||
def _initialize_from_pdb(self, path): | ||
""" | ||
It initializes a molecule with the molecule structure read from | ||
|
@@ -585,6 +615,9 @@ def _initialize_from_pdb(self, path): | |
logger.info(' - Initializing molecule from PDB') | ||
self._initialize() | ||
|
||
#Validate PDB | ||
self._PDB_checkup(path) | ||
|
||
logger.info(' - Loading molecule from RDKit') | ||
rdkit_toolkit = RDKitToolkitWrapper() | ||
self._rdkit_molecule = rdkit_toolkit.from_pdb(path) | ||
|
Be careful when using Python's built-in names such as
list
orid
. It is not recommended.