Skip to content

Commit

Permalink
more robust DCD writer
Browse files Browse the repository at this point in the history
  • Loading branch information
stefdoerr committed Jan 3, 2024
1 parent aa75b4d commit 46515d4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions moleculekit/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,18 @@ def DCDwrite(mol, filename):
from moleculekit.dcd import DCDTrajectoryFile

xyz = np.transpose(mol.coords, (2, 0, 1))
box = mol.box.T
boxangles = mol.boxangles.T
n_frames = xyz.shape[0]

if not np.all(mol.box == 0):
box = mol.box.T
else:
box = np.zeros((n_frames, 3), dtype=np.float32)

if not np.all(mol.boxangles == 0):
boxangles = mol.boxangles.T
else:
boxangles = np.zeros((n_frames, 3), dtype=np.float32)

with DCDTrajectoryFile(filename, "w") as fh:
fh.write(xyz, cell_lengths=box, cell_angles=boxangles)

Expand Down

0 comments on commit 46515d4

Please sign in to comment.