Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: multipucker #1611

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pytraj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions pytraj/all_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
'ti',
'lipidscd',
'xtalsymm',
'multipucker',
'hausdorff',
'permute_dihedrals',
]
Expand Down Expand Up @@ -3114,6 +3115,21 @@ def xtalsymm(traj, mask='', options='', ref=None, **kwargs):
return traj


@super_dispatch()
def multipucker(traj, options='', dtype='dict', top=None, frame_indices=None):
'''

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,
Expand Down
11 changes: 11 additions & 0 deletions pytraj/analysis/c_action/c_action.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions pytraj/analysis/c_action/c_action.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
20 changes: 20 additions & 0 deletions tests/test_analysis/test_multipucker.py
Original file line number Diff line number Diff line change
@@ -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)
31 changes: 11 additions & 20 deletions tests/test_analysis/test_pucker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python

from __future__ import print_function
import unittest
import pytraj as pt
from utils import fn
Expand All @@ -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)
22 changes: 11 additions & 11 deletions tests/test_io/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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])
Expand Down