fixed chain bug

This commit is contained in:
2026-03-11 15:20:26 +01:00
parent 6f17c41ea3
commit d16c968482
+29 -14
View File
@@ -180,24 +180,35 @@ def check_occupancies(struct):
# -----------------------------
def check_missing_light_residues(dark, light, ensemble):
dark_res = {(c.name, r.seqid.num, r.name) for c in dark[0] for r in c}
light_res = {(c.name, r.seqid.num, r.name) for c in light[0] for r in c}
ens_res = {(c.name, r.seqid.num, r.name) for c in ensemble[0] for r in c}
ens_atoms = {
(c.name, r.seqid.num, r.name, a.name)
for c in ensemble[0]
for r in c
for a in r
}
missing = light_res - ens_res
missing = []
for chain in light[0]:
for res in chain:
for atom in res:
key = (chain.name, res.seqid.num, res.name, atom.name)
if key not in ens_atoms:
missing.append(key)
if missing:
print()
print("ERROR: residues lost from light structure during merge")
print("------------------------------------------------------")
print("ERROR: atoms lost from light structure during merge")
print("---------------------------------------------------")
for r in sorted(missing):
print(" ", r)
for m in missing[:20]:
print(" ", m)
print()
print("Ensemble construction aborted.")
print("Check residue creation or atom filtering.")
print()
sys.exit(1)
@@ -258,11 +269,15 @@ def build_ensemble(dark, light, light_occ, occ_cutoff=0.005, verbose=False):
if target_res is None:
target_res = gemmi.Residue()
target_res.name = res.name
target_res.seqid = gemmi.SeqId(res.seqid.num, res.seqid.icode)
new_res = gemmi.Residue()
new_res.name = res.name
new_res.seqid = gemmi.SeqId(res.seqid.num, res.seqid.icode)
target_chain.add_residue(new_res)
# IMPORTANT: retrieve the actual residue stored in the chain
target_res = target_chain[-1]
target_chain.add_residue(target_res)
res_lookup[key] = target_res
for atom in res:
@@ -306,7 +321,7 @@ def build_ensemble(dark, light, light_occ, occ_cutoff=0.005, verbose=False):
# -----------------------------
# Mainfsortdcdds
# Main
# -----------------------------
def main():