From 412984e609e8f01822e80eb916f26275178c4fb7 Mon Sep 17 00:00:00 2001 From: Hai Nguyen Date: Fri, 24 Jun 2022 18:02:50 -0400 Subject: [PATCH 1/2] multipucker --- pytraj/all_actions.py | 16 ++++++++++++++++ pytraj/analysis/c_action/c_action.pxd | 11 +++++++++++ pytraj/analysis/c_action/c_action.pyx | 16 ++++++++++++++++ tests/test_io/test_io.py | 22 +++++++++++----------- 4 files changed, 54 insertions(+), 11 deletions(-) diff --git a/pytraj/all_actions.py b/pytraj/all_actions.py index 0eb55ed7b..59f161981 100644 --- a/pytraj/all_actions.py +++ b/pytraj/all_actions.py @@ -133,6 +133,7 @@ 'ti', 'lipidscd', 'xtalsymm', + 'multipucker', 'hausdorff', 'permute_dihedrals', ] @@ -3114,6 +3115,21 @@ def xtalsymm(traj, mask='', options='', ref=None, **kwargs): return traj +@super_dispatch() +def multipucker(traj, options='', dtype='dict'): + ''' + + Parameters + ---------- + traj : Trajectory-like + options : str, cpptraj's options + See `pytraj.info("multipucker")` for further information. + ''' + command = options + c_dslist, _ = do_action(traj, command, c_action.Action_MultiPucker) + return get_data_from_dtype(c_dslist, dtype=dtype) + + def analyze_modes(mode_type, eigenvectors, eigenvalues, diff --git a/pytraj/analysis/c_action/c_action.pxd b/pytraj/analysis/c_action/c_action.pxd index 78b2fabcd..a4585f438 100644 --- a/pytraj/analysis/c_action/c_action.pxd +++ b/pytraj/analysis/c_action/c_action.pxd @@ -972,3 +972,14 @@ cdef extern from "Action_XtalSymm.h": cdef class Action_XtalSymm(Action): cdef _Action_XtalSymm* thisptr + + +cdef extern from "Action_MultiPucker.h": + cdef cppclass _Action_MultiPucker "Action_MultiPucker" (_Action) nogil: + _Action_MultiPucker() + _DispatchObject * Alloc() + void Help() + + +cdef class Action_MultiPucker(Action): + cdef _Action_MultiPucker* thisptr diff --git a/pytraj/analysis/c_action/c_action.pyx b/pytraj/analysis/c_action/c_action.pyx index 0d90b04cf..3c600fadf 100644 --- a/pytraj/analysis/c_action/c_action.pyx +++ b/pytraj/analysis/c_action/c_action.pyx @@ -1280,6 +1280,7 @@ cdef class Action_Volume(Action): def help(self): self.thisptr.Help() + cdef class Action_Watershell(Action): def __cinit__(self): self.baseptr = <_Action*> new _Action_Watershell() @@ -1293,6 +1294,7 @@ cdef class Action_Watershell(Action): def help(self): self.thisptr.Help() + cdef class Action_XtalSymm(Action): def __cinit__(self): self.baseptr = <_Action*> new _Action_XtalSymm() @@ -1305,3 +1307,17 @@ cdef class Action_XtalSymm(Action): def help(self): self.thisptr.Help() + + +cdef class Action_MultiPucker(Action): + def __cinit__(self): + self.baseptr = <_Action*> new _Action_MultiPucker() + self.thisptr = <_Action_MultiPucker*> self.baseptr + self.own_memory = True + + def __dealloc__(self): + if self.baseptr is not NULL and self.own_memory: + del self.baseptr + + def help(self): + self.thisptr.Help() diff --git a/tests/test_io/test_io.py b/tests/test_io/test_io.py index 72d446bc5..3a24d0dad 100644 --- a/tests/test_io/test_io.py +++ b/tests/test_io/test_io.py @@ -444,8 +444,8 @@ def add_velocity(traj): for frame in add_velocity(traj): writer.write(frame) traj2 = pt.iterload(out_fn, top=traj.top) - assert traj2.metadata['has_velocity'] - assert not traj2.metadata['has_force'] + assert traj2.crdinfo['has_velocity'] + assert not traj2.crdinfo['has_force'] # make sure no segmentation fault # issues/1486 assert traj2[:].n_frames == traj2.n_frames @@ -469,8 +469,8 @@ def add_force(traj): for frame in add_force(traj): writer.write(frame) traj2 = pt.iterload(out_fn, top=traj.top) - assert traj2.metadata['has_force'] - assert not traj2.metadata['has_velocity'] + assert traj2.crdinfo['has_force'] + assert not traj2.crdinfo['has_velocity'] # issues/1486 assert traj2[:].n_frames == traj2.n_frames @@ -498,24 +498,24 @@ def add_force_and_velocity(traj): for frame in add_force_and_velocity(traj): writer.write(frame) traj2 = pt.iterload(out_fn, top=traj.top) - assert traj2.metadata['has_force'] - assert traj2.metadata['has_velocity'] + assert traj2.crdinfo['has_force'] + assert traj2.crdinfo['has_velocity'] def test_write_force_and_velocity(): trajin = cpptraj_test_dir + '/Test_systemVF/systemVF.nc' tn = cpptraj_test_dir + '/Test_systemVF/systemVF.parm7' traj = pt.iterload(trajin, tn) - assert traj.metadata['has_force'] - assert traj.metadata['has_velocity'] + assert traj.crdinfo['has_force'] + assert traj.crdinfo['has_velocity'] with tempfolder(): fn2 = 'test.nc' - traj.save(fn2, overwrite=True, crdinfo=traj.metadata) + traj.save(fn2, overwrite=True, crdinfo=traj.crdinfo) traj2 = pt.iterload(fn2, traj.top) - assert traj2.metadata['has_force'] - assert traj2.metadata['has_velocity'] + assert traj2.crdinfo['has_force'] + assert traj2.crdinfo['has_velocity'] forces_traj = np.array([frame.force.copy() for frame in traj]) forces_traj2 = np.array([frame.force.copy() for frame in traj2]) From d9797d350e8cad6e1fd3d3c673bf94e4472632cc Mon Sep 17 00:00:00 2001 From: Hai Nguyen Date: Fri, 24 Jun 2022 18:09:27 -0400 Subject: [PATCH 2/2] more --- pytraj/__init__.py | 1 + pytraj/all_actions.py | 2 +- tests/test_analysis/test_multipucker.py | 20 ++++++++++++++++ tests/test_analysis/test_pucker.py | 31 +++++++++---------------- 4 files changed, 33 insertions(+), 21 deletions(-) create mode 100644 tests/test_analysis/test_multipucker.py diff --git a/pytraj/__init__.py b/pytraj/__init__.py index 1cbeeeee4..dc9388c0c 100644 --- a/pytraj/__init__.py +++ b/pytraj/__init__.py @@ -188,6 +188,7 @@ from .all_actions import ti from .all_actions import lipidscd from .all_actions import xtalsymm +from .all_actions import multipucker from .all_actions import hausdorff from .all_actions import permute_dihedrals diff --git a/pytraj/all_actions.py b/pytraj/all_actions.py index 59f161981..44b61d5d9 100644 --- a/pytraj/all_actions.py +++ b/pytraj/all_actions.py @@ -3116,7 +3116,7 @@ def xtalsymm(traj, mask='', options='', ref=None, **kwargs): @super_dispatch() -def multipucker(traj, options='', dtype='dict'): +def multipucker(traj, options='', dtype='dict', top=None, frame_indices=None): ''' Parameters diff --git a/tests/test_analysis/test_multipucker.py b/tests/test_analysis/test_multipucker.py new file mode 100644 index 000000000..271d79eb0 --- /dev/null +++ b/tests/test_analysis/test_multipucker.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +import unittest +import pytraj as pt +from utils import fn +from pytraj.testing import aa_eq + +cm = ''' +multipucker +''' + +def test_multipucker(): + traj = pt.iterload(fn('Test_NAstruct/adh026.3.pdb')) + state = pt.load_cpptraj_state(cm, traj) + state.run() + + print(state.data[1:]) + + data = pt.multipucker(traj) + print(data) diff --git a/tests/test_analysis/test_pucker.py b/tests/test_analysis/test_pucker.py index 6953ffab9..c97d66314 100644 --- a/tests/test_analysis/test_pucker.py +++ b/tests/test_analysis/test_pucker.py @@ -1,6 +1,5 @@ #!/usr/bin/env python -from __future__ import print_function import unittest import pytraj as pt from utils import fn @@ -16,24 +15,16 @@ ''' -class TestPucker(unittest.TestCase): - '''TestPucker - ''' +def test_pucker(): + traj = pt.iterload(fn('Test_NAstruct/adh026.3.pdb')) + state = pt.load_cpptraj_state(cm, traj) + state.run() - def test_pucker(self): - traj = pt.iterload(fn('Test_NAstruct/adh026.3.pdb')) - state = pt.load_cpptraj_state(cm, traj) - state.run() + data_altona = pt.pucker(traj, resrange=range(3)) + data_cremer = pt.pucker(traj, resrange=range(3), method='cremer') + aa_eq(data_altona.values, state.data[1:4].values) + aa_eq(data_cremer.values, state.data[4:].values) - data_altona = pt.pucker(traj, resrange=range(3)) - data_cremer = pt.pucker(traj, resrange=range(3), method='cremer') - aa_eq(data_altona.values, state.data[1:4].values) - aa_eq(data_cremer.values, state.data[4:].values) - - # resrange=None - data_full_residues = pt.pucker(traj, resrange=None) - aa_eq(data_full_residues[:3].values, data_altona[:3].values) - - -if __name__ == "__main__": - unittest.main() + # resrange=None + data_full_residues = pt.pucker(traj, resrange=None) + aa_eq(data_full_residues[:3].values, data_altona[:3].values)