Skip to content

Commit a900985

Browse files
committed
fix superpositon bug in reports
1 parent a69b49b commit a900985

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

bin/generate_comparison_report.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def align_structures(structures):
122122

123123
def get_atom_ids(structure):
124124
# Note: this is a *set* of atom_ids due to the {} surrounding the comprehension
125-
return {(atom.get_parent().get_id(), atom.name) for atom in structure.get_atoms()}
125+
return {(atom.get_parent().get_parent().get_id(), atom.get_parent().get_id(), atom.name) for atom in structure.get_atoms() if atom.element != 'H'}
126126

127127
# TODO: do we want to raise and error if the structures are not identical atomically, or keep the ability to sub-align?
128128
# Update the atoms shared between structures with progressive intersections
@@ -137,7 +137,7 @@ def get_atom_ids(structure):
137137
#print(common_atoms)
138138
def extract_atoms(structure, atom_ids):
139139
# Note: this comprehension returns an atom *object* for each atom in the structure
140-
return [atom for atom in structure.get_atoms() if (atom.get_parent().get_id(), atom.name) in atom_ids]
140+
return [atom for atom in structure.get_atoms() if (atom.get_parent().get_parent().get_id(), atom.get_parent().get_id(), atom.name) in atom_ids]
141141

142142
ref_atoms = extract_atoms(ref_structure, common_atoms)
143143
# The aligned structures will be the parsed structures aligned to the common atoms of the reference structure

bin/generate_report.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,22 @@ def align_structures(structures):
219219
ref_structure = structures[0]
220220

221221
common_atoms = set(
222-
f"{atom.get_parent().get_id()[1]}-{atom.name}"
223-
for atom in ref_structure.get_atoms()
222+
f"{atom.get_parent().get_parent().get_id()}-{atom.get_parent().get_id()[1]}-{atom.name}"
223+
for atom in ref_structure.get_atoms() if not atom.element == 'H'
224224
)
225+
#print(common_atoms)
225226
for i, structure in enumerate(structures[1:], start=1):
226227
common_atoms = common_atoms.intersection(
227228
set(
228-
f"{atom.get_parent().get_id()[1]}-{atom.name}"
229+
f"{atom.get_parent().get_parent().get_id()}-{atom.get_parent().get_id()[1]}-{atom.name}"
229230
for atom in structure.get_atoms()
230231
)
231232
)
232233

233234
ref_atoms = [
234235
atom
235236
for atom in ref_structure.get_atoms()
236-
if f"{atom.get_parent().get_id()[1]}-{atom.name}" in common_atoms
237+
if f"{atom.get_parent().get_parent().get_id()}-{atom.get_parent().get_id()[1]}-{atom.name}" in common_atoms
237238
]
238239
# print(ref_atoms)
239240
super_imposer = PDB.Superimposer()
@@ -243,7 +244,7 @@ def align_structures(structures):
243244
target_atoms = [
244245
atom
245246
for atom in structure.get_atoms()
246-
if f"{atom.get_parent().get_id()[1]}-{atom.name}" in common_atoms
247+
if f"{atom.get_parent().get_parent().get_id()}-{atom.get_parent().get_id()[1]}-{atom.name}" in common_atoms
247248
]
248249

249250
super_imposer.set_atoms(ref_atoms, target_atoms)

0 commit comments

Comments
 (0)