Skip to content

Commit 92af45b

Browse files
committed
Change shift to enable other boxes
1 parent 5e135ab commit 92af45b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/openfe_analysis/rmsd.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,20 @@ def __init__(self, prot, max_threads=1):
2323
super().__init__()
2424

2525
def _transform(self, ts):
26+
# Get coordinates of all chains
2627
chains = [seg.atoms for seg in self.prot.segments]
2728
ref_chain = chains[0]
29+
# Wrap all chains into the same box relative to ref_chain
2830
for chain in chains[1:]:
31+
# Compute COM difference (how far the chain is from ref chain)
2932
vec = chain.center_of_mass() - ref_chain.center_of_mass()
30-
chain.positions -= np.rint(vec / ts.dimensions[:3]) * ts.dimensions[:3]
33+
# Wrap positions relative to ref_chain COM
34+
# np.linalg.solve: Convert Cartesian vec to fractional coordinates
35+
# np.round: Get nearest integer box translation
36+
# np.dot: Convert back to Cartesian
37+
chain.positions -= np.dot(np.round(np.linalg.solve(ts.cell, vec)),ts.cell)
38+
# This only works for cubic cells
39+
# chain.positions -= np.rint(vec / ts.dimensions[:3]) * ts.dimensions[:3]
3140
return ts
3241

3342

0 commit comments

Comments
 (0)