From 53100b0b47fcec46c64c20677c81be29822abf0c Mon Sep 17 00:00:00 2001 From: Timothy Click Date: Sat, 14 Oct 2017 16:40:56 +0800 Subject: [PATCH 1/2] Fixed a bug in the COR module. Fixed some bugs in the tests. Signed-off-by: Timothy Click --- src/fluctmatch/coordinates/COR.py | 8 ++++---- tests/fluctmatch/test_utils.py | 27 +++++++++++++++++++++++++-- tests/test_fluctmatch.py | 1 - 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/fluctmatch/coordinates/COR.py b/src/fluctmatch/coordinates/COR.py index 08e3ea0..5f9e482 100644 --- a/src/fluctmatch/coordinates/COR.py +++ b/src/fluctmatch/coordinates/COR.py @@ -77,16 +77,16 @@ class CORWriter(CRD.CRDWriter): # crdtype = "extended" # fortran_format = "(2I10,2X,A8,2X,A8,3F20.10,2X,A8,2X,A8,F20.10)" ATOM_EXT=( - "{serial:10d}{totRes:10d} {resname:<8.8s} {name:<8.8s}"" - "{pos[0]:20.10f}{pos[1]:20.10f}{pos[2]:20.10f} "" + "{serial:10d}{totRes:10d} {resname:<8.8s} {name:<8.8s}" + "{pos[0]:20.10f}{pos[1]:20.10f}{pos[2]:20.10f} " "{chainID:<8.8s} {resSeq:<8d}{tempfactor:20.10f}\n" ), NUMATOMS_EXT="{0:10d} EXT\n", # crdtype = "standard" # fortran_format = "(2I5,1X,A4,1X,A4,3F10.5,1X,A4,1X,A4,F10.5)" ATOM=( - "{serial:5d}{totRes:5d} {resname:<4.4s} {name:<4.4s}"" - "{pos[0]:10.5f}{pos[1]:10.5f}{pos[2]:10.5f} "" + "{serial:5d}{totRes:5d} {resname:<4.4s} {name:<4.4s}" + "{pos[0]:10.5f}{pos[1]:10.5f}{pos[2]:10.5f} " "{chainID:<4.4s} {resSeq:<4d}{tempfactor:10.5f}\n" ), TITLE="* FRAME {frame} FROM {where}\n", diff --git a/tests/fluctmatch/test_utils.py b/tests/fluctmatch/test_utils.py index 2bbe7ea..c76d71f 100644 --- a/tests/fluctmatch/test_utils.py +++ b/tests/fluctmatch/test_utils.py @@ -53,7 +53,7 @@ def test_average_bonds(): universe.bonds.bonds() for _ in universe.trajectory ], axis=0) - bonds = fmutils.BondStats(universe, func="mean").run().result + (bonds, ) = fmutils.BondStats(universe, func="mean").run().result testing.assert_allclose( bonds["r_IJ"], avg_bonds, @@ -67,9 +67,32 @@ def test_bond_fluctuation(): universe.bonds.bonds() for _ in universe.trajectory ], axis=0) - bonds = fmutils.BondStats(universe, func="std").run().result + (bonds, ) = fmutils.BondStats(universe, func="std").run().result testing.assert_allclose( bonds["r_IJ"], bond_fluct, err_msg=native_str("Bond fluctuations don't match."), ) + + +def test_bond_all_stats(): + universe = mda.Universe(TPR, XTC) + bond_average = np.mean([ + universe.bonds.bonds() + for _ in universe.trajectory + ], axis=0) + bond_fluct = np.std([ + universe.bonds.bonds() + for _ in universe.trajectory + ], axis=0) + (average, std) = fmutils.BondStats(universe, func="both").run().result + testing.assert_allclose( + std["r_IJ"], + bond_fluct, + err_msg=native_str("Bond fluctuations don't match."), + ) and testing.assert_allclose( + average["r_IJ"], + bond_fluct, + err_msg=native_str("Bond fluctuations don't match."), + ) + diff --git a/tests/test_fluctmatch.py b/tests/test_fluctmatch.py index 067abca..a0c34a9 100644 --- a/tests/test_fluctmatch.py +++ b/tests/test_fluctmatch.py @@ -30,5 +30,4 @@ def test_main(): runner = CliRunner() result = runner.invoke(main, []) - assert result.output == "()\n" assert result.exit_code == 0 From f584058d12840ec59df76b66ee1d71fb3310f7be Mon Sep 17 00:00:00 2001 From: Timothy Click Date: Sat, 14 Oct 2017 16:44:25 +0800 Subject: [PATCH 2/2] Fixed a bug that may cause some topology files (i.e., GRO) to fail. Signed-off-by: Timothy Click --- src/fluctmatch/models/trajectory.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/fluctmatch/models/trajectory.py b/src/fluctmatch/models/trajectory.py index 9bc699d..8d3a2b3 100644 --- a/src/fluctmatch/models/trajectory.py +++ b/src/fluctmatch/models/trajectory.py @@ -145,18 +145,24 @@ def _fill_ts(self, other_ts): residues, viewitems(self._mapping) ) if self.ts.has_velocities: - self.ts._velocities[:] = [ - res.select_atoms(selection).velocities.sum() - for res, (_, selection) in residue_selection - if res.select_atoms(selection) - ] + try: + self.ts._velocities[:] = [ + res.select_atoms(selection).velocities.sum() + for res, (_, selection) in residue_selection + if res.select_atoms(selection) + ] + except ValueError: + pass if self.ts.has_forces: - self.ts._forces[:] = [ - res.select_atoms(selection).forces.sum() - for res, (_, selection) in residue_selection - if res.select_atoms(selection) - ] + try: + self.ts._forces[:] = [ + res.select_atoms(selection).forces.sum() + for res, (_, selection) in residue_selection + if res.select_atoms(selection) + ] + except ValueError: + pass def _reopen(self): # Rewind my reference trajectory