Skip to content

Commit 3972897

Browse files
committed
CIF readers now also set box size and angles if the information is available
1 parent 6d9320f commit 3972897

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

moleculekit/readers.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,11 +2047,11 @@ def fixDefault(val, dtype):
20472047

20482048
# Parsing CRYST1 data
20492049
cryst = dataObj.getObj("cell")
2050+
crystalinfo = {}
20502051
if cryst is not None and cryst.getRowCount() == 1:
20512052
row = cryst.getRow(0)
20522053
attrs = cryst.getAttributeList()
20532054

2054-
crystalinfo = {}
20552055
for source_field, target in cryst1_mapping.items():
20562056
if source_field not in attrs:
20572057
continue
@@ -2317,7 +2317,18 @@ def fixDefault(val, dtype):
23172317

23182318
if not macromolecule:
23192319
topo.record = ["HETATM"] * len(topo.name)
2320-
return MolFactory.construct(topo, Trajectory(coords=coords), filename, frame)
2320+
2321+
box = None
2322+
boxangles = None
2323+
if "a" in crystalinfo and "b" in crystalinfo and "c" in crystalinfo:
2324+
box = np.array([crystalinfo["a"], crystalinfo["b"], crystalinfo["c"]])
2325+
if "alpha" in crystalinfo and "beta" in crystalinfo and "gamma" in crystalinfo:
2326+
boxangles = np.array(
2327+
[crystalinfo["alpha"], crystalinfo["beta"], crystalinfo["gamma"]]
2328+
)
2329+
return MolFactory.construct(
2330+
topo, Trajectory(coords=coords, box=box, boxangles=boxangles), filename, frame
2331+
)
23212332

23222333

23232334
_ATOM_TYPE_REG_EX = re.compile(r"^\S+x\d+$")
@@ -3819,6 +3830,11 @@ def test_bcif_pdb(self):
38193830
mol2.bonds = np.zeros((0, 2), dtype=np.uint32)
38203831
mol2.bondtype = np.zeros((0,), dtype=object)
38213832

3833+
extra_except = []
3834+
if pdbid == "6a5j":
3835+
# The CIF file is missing crystal info
3836+
extra_except = ["box", "boxangles"]
3837+
38223838
assert mol_equal(
38233839
mol1,
38243840
mol2,
@@ -3829,7 +3845,8 @@ def test_bcif_pdb(self):
38293845
"segid",
38303846
"serial",
38313847
"bondtype",
3832-
],
3848+
]
3849+
+ extra_except,
38333850
)
38343851

38353852
def test_inpcrd(self):

0 commit comments

Comments
 (0)