Skip to content

Commit dccd271

Browse files
committed
Fix a few bugs to do with counting hetatm residues
1 parent f5bccb9 commit dccd271

4 files changed

Lines changed: 26 additions & 7 deletions

File tree

prepmd/get_residues.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
except:
1010
NO_MODELLER = True
1111
from prepmd import util
12+
from prepmd import ligand
1213

1314

1415
def get_residues_pdb(pdb, code, get_hetatms=False):
@@ -76,13 +77,23 @@ def get_fullseq_pdb(pdb, code, get_hetatms=False):
7677
sequence = line.split()[2]
7778
seqres[chain] .append(sequence)
7879
if line.startswith("#"):
79-
reading_seq = False # TODO: option to add marker for hetatms
80+
reading_seq = False
8081
if line.startswith("HET") and not hetatms_found and get_hetatms:
8182
hetatms_found = True
8283

8384
if hetatms_found:
85+
# count hetatm residues and add an equivalent number of "." entries in
86+
# the fasta sequence
87+
universe = ligand.load_universe(pdb)
88+
ligands = universe.select_atoms('not protein and not water')
89+
num_hetatm_residues = len(ligands.split("residue"))
8490
last_key = sorted(seqres.keys())[-1]
85-
seqres[last_key] += ["..."] # not '.h.'?
91+
seqres[last_key] += [num_hetatm_residues*"."]
92+
93+
94+
if get_hetatms and not hetatms_found:
95+
raise ValueError("Was told to retrieve hetatms from "+pdb+" but none "
96+
"were found.")
8697

8798
# convert to fasta
8899
fastas = []

prepmd/ligand.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,3 +369,9 @@ def create_ligand_system(
369369
# intergrator - variable langevin, tolerance: 0.0005 (or timestep < 0.001ps)
370370
# minimisation - tolerance = 2.5 kilojoule/(nanometer*mole)
371371
return openmm_system, openmm_topology, openmm_positions
372+
373+
374+
def get_ligand_centroid(pdb, traj):
375+
universe = load_universe(pdb)
376+
377+
ligand = u.select_atoms('not protein and not water')

prepmd/prep.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ def in_string(substr, text): return text == None or substr in text.lower()
274274
no_sim_output = False
275275
if split_hetatms:
276276
ligands = ligand.split_pdb_ligand(inmodel)
277-
#if ligands and split_hetatms:
278277
print("Wrote hetatms/ligands to "+", ".join(ligands))
279278
no_sim_output = True # don't minimise the ligandless structure without
280279
# the ligands!

prepmd/util.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"XAA": "X",
2929
"TYR": "Y",
3030
"GLX": "Z",
31-
".h.": ".h." # leave hetatms
3231
}
3332

3433

@@ -40,7 +39,7 @@ def is_residue(resid):
4039
Returns:
4140
a boolean that is true if the string is a valid residue
4241
"""
43-
return resid in codes
42+
return resid in codes or list(set(resid)) == ["."]
4443

4544

4645
def is_residue_sequence(sequence):
@@ -68,6 +67,8 @@ def three_to_one(resid, ignore_non_standard=False):
6867
Returns:
6968
the fasta residue, a string
7069
"""
70+
if list(set(resid)) == ["."]: # hetatms
71+
return resid
7172
if is_residue(resid):
7273
return codes[resid]
7374
if ignore_non_standard:
@@ -85,11 +86,13 @@ def three_to_one_sequence(resids):
8586
Returns:
8687
the residue sequence in FASTA format
8788
"""
89+
print(resids)
8890
pdb_sequence = ""
8991
non_standard = []
9092
for resid in resids:
9193
try:
92-
pdb_sequence += codes[resid]
93-
except KeyError:
94+
pdb_sequence += three_to_one(resid)
95+
except ValueError:
9496
non_standard.append(resid)
97+
print(pdb_sequence)
9598
return pdb_sequence

0 commit comments

Comments
 (0)