Skip to content

Commit

Permalink
Merge branch 'main' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
florianjoerg authored Sep 5, 2023
2 parents 96632c1 + 2051908 commit a7cf442
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
17 changes: 17 additions & 0 deletions protex/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""helpers.py contains additional functions for easier use of protex."""
from MDAnalysis.coordinates.base import SingleFrameReaderBase
from MDAnalysis.lib.util import openany
from openmm import XmlSerializer
from parmed.formats import PSFFile
from parmed.topologyobjects import DrudeAtom, ExtraPoint, LocalCoordinatesFrame

Expand All @@ -8,6 +11,20 @@
from parmed.utils.io import genopen


class XMLSingleReader(SingleFrameReaderBase):
format = "rst"
units = {"time": "ps", "length": "Nanometer"}
_format_type = "xml"

def _read_first_frame(self):
with openany(self.filename) as xmlfile:
state = XmlSerializer.deserialize(xmlfile.read())
positions = state.getPositions(asNumpy=True)
self.n_atoms = positions.shape[0]
self.ts = self._Timestep.from_coordinates(positions, **self._ts_kwargs)
self.ts.frame = 0


class CustomPSFFile(PSFFile):
"""
Child of parmeds formats/psf.py PFSFile class
Expand Down
26 changes: 26 additions & 0 deletions protex/tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os

import pytest

from protex.helpers import XMLSingleReader


@pytest.mark.skipif(
os.getenv("CI") == "true",
reason="No MDAnalysis",
)
def test_XMLSingleReader():
a = XMLSingleReader("protex/forcefield/traj/im1h_oac_150_im1_hoac_350_npt_7.rst")

@pytest.mark.skipif(
os.getenv("CI") == "true",
reason="No MDAnalysis",
)
def test_Universe():
import MDAnalysis
u = MDAnalysis.Universe("protex/forcefield/im1h_oac_150_im1_hoac_350.psf","protex/forcefield/traj/im1h_oac_150_im1_hoac_350_npt_7.rst")
#print(u.trajectory.n_frames)
#print(u.trajectory.n_atoms)
#print(dir(u.trajectory))
sel = u.select_atoms("all")
#print(sel.positions)

0 comments on commit a7cf442

Please sign in to comment.