stk: Remove `pdb` from init_from_file options for BuildingBlock
The minimum working example at the bottom shows clearly that if you write
and then init_from_file
, you will lose bond order information. This is because PDB files do not contain bond order information in their “CONECT” records.
Therefore, I suggest removing it as an init function (the with_structure_from_file
method is completely fine because it just loads the coordinates). Perhaps a warning is added for 6 months before removing?
What do you think, @lukasturcani?
import stk
from collections import Counter
pdb_writer = stk.PdbWriter()
bb = stk.BuildingBlock(
'CN(c1ccc(cc1)N=Cc2cccnc2)c3nc(nc(n3)N(C)c4ccc(cc4)N=Cc5ccccn5)'
'N(C)c6ccc(cc6)N=Cc7ccccn7'
)
# Get bond order information.
orders = []
for bond in bb.get_bonds():
orders.append(bond.get_order())
# Write to PDB.
bb.write(f'first.pdb')
# Read from PDB.
bb2 = stk.BuildingBlock.init_from_file('first.pdb')
# Get bond order information.
orders2 = []
for bond in bb2.get_bonds():
orders2.append(bond.get_order())
print(Counter(orders), Counter(orders2)) ## >> Counter({1.0: 72, 2.0: 24}) Counter({1.0: 96})
# Write to PDB.
bb.write(f'second.pdb')
# Compare text of PDBs.
s1 = pdb_writer.to_string(bb)
s2 = pdb_writer.to_string(bb2)
print(s1 == s2)
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (8 by maintainers)
fair, we write XYZ files which do not preserve bond orders. so thats not too crazy