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

Make CRD EXT format optional #3635

Merged
merged 25 commits into from
Apr 18, 2022
Merged
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6d6a55e
CRD extended format an option for small systems
mdpoleto Apr 13, 2022
9c64f40
make CRD EXT format optional
mdpoleto Apr 13, 2022
beb6159
make CRD EXT format optional
mdpoleto Apr 13, 2022
1aec9f8
make CRD EXT format optional
mdpoleto Apr 13, 2022
ca4b46b
Update package/MDAnalysis/coordinates/CRD.py
mdpoleto Apr 14, 2022
6437458
Update package/MDAnalysis/coordinates/CRD.py
mdpoleto Apr 14, 2022
a2d0353
Update package/MDAnalysis/coordinates/CRD.py
mdpoleto Apr 14, 2022
53494d5
Update package/MDAnalysis/coordinates/CRD.py
mdpoleto Apr 14, 2022
430c4b8
Simplifying CRD extended code
mdpoleto Apr 14, 2022
6a4f04b
Include tests for CRD ext format
mdpoleto Apr 14, 2022
714945e
Include tests for CRD ext format
mdpoleto Apr 14, 2022
f304346
Include tests for CRD ext format
mdpoleto Apr 15, 2022
cf061f1
Improve tests for CRD EXT format
mdpoleto Apr 15, 2022
1419ab9
to be overwritten
mdpoleto Apr 15, 2022
b10ec16
Merge branch 'develop' of https://github.com/MDAnalysis/mdanalysis in…
mdpoleto Apr 15, 2022
eedd551
Merge branch 'MDAnalysis-develop' into issue-3605
mdpoleto Apr 15, 2022
c3cf075
update AUTHORS
mdpoleto Apr 15, 2022
9077a6d
Update package/MDAnalysis/coordinates/CRD.py
mdpoleto Apr 16, 2022
4765c8f
Add test to read EXT format
mdpoleto Apr 16, 2022
b11b6c4
Improve test to read EXT format
mdpoleto Apr 16, 2022
53c93e3
Merge branch 'develop' of https://github.com/MDAnalysis/mdanalysis in…
mdpoleto Apr 18, 2022
30ffb41
Update AUTHORS
mdpoleto Apr 18, 2022
276b0b7
Update AUTHORS and CRD read tests
mdpoleto Apr 18, 2022
04879c3
Update AUTHORS and CRD read tests
mdpoleto Apr 18, 2022
2d3819e
Apply suggestions from code review
orbeckst Apr 18, 2022
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
42 changes: 36 additions & 6 deletions package/MDAnalysis/coordinates/CRD.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class CRDWriter(base.WriterBase):

.. versionchanged:: 0.11.0
Frames now 0-based instead of 1-based
.. versionchanged:: 0.12.0
mdpoleto marked this conversation as resolved.
Show resolved Hide resolved
CRD extended format now can be explicitely requested
mdpoleto marked this conversation as resolved.
Show resolved Hide resolved
"""
format = 'CRD'
units = {'time': None, 'length': 'Angstrom'}
Expand All @@ -151,12 +153,23 @@ def __init__(self, filename, **kwargs):
----------
filename : str or :class:`~MDAnalysis.lib.util.NamedStream`
name of the output file or a stream

crdext : bool (optional)
mdpoleto marked this conversation as resolved.
Show resolved Hide resolved
By default, noextended CRD format is used [``False``].
However, extended CRD format can be forced by
specifying `crdext` ``=True``.
mdpoleto marked this conversation as resolved.
Show resolved Hide resolved
"""

self.filename = util.filename(filename, ext='crd')
self.crd = None

def write(self, selection, frame=None):
# account for explicit crd format, if requested
if "crdext" in kwargs.keys():
self.crdext = kwargs.pop('crdext')
else:
self.crdext = False # if not requested, default to NOEXT format
mdpoleto marked this conversation as resolved.
Show resolved Hide resolved

def write(self, selection, frame=None, crdext=False):
mdpoleto marked this conversation as resolved.
Show resolved Hide resolved
"""Write selection at current trajectory frame to file.

Parameters
Expand All @@ -182,23 +195,37 @@ def write(self, selection, frame=None):
except AttributeError:
frame = 0 # should catch cases when we are analyzing a single PDB (?)

# account for explicit crd format, if requested
if self.crdext:
crdext = self.crdext
else:
crdext = crdext # if not requested, default to NOEXT format

mdpoleto marked this conversation as resolved.
Show resolved Hide resolved

atoms = selection.atoms # make sure to use atoms (Issue 46)
coor = atoms.positions # can write from selection == Universe (Issue 49)

n_atoms = len(atoms)
# Detect which format string we're using to output (EXT or not)
# *len refers to how to truncate various things,
# depending on output format!

if n_atoms > 99999:
mdpoleto marked this conversation as resolved.
Show resolved Hide resolved
at_fmt = self.fmt['ATOM_EXT']
serial_len = 10
resid_len = 8
totres_len = 10
else:
at_fmt = self.fmt['ATOM']
serial_len = 5
resid_len = 4
totres_len = 5
if crdext is True:
at_fmt = self.fmt['ATOM_EXT']
serial_len = 10
resid_len = 8
totres_len = 10
else:
at_fmt = self.fmt['ATOM']
serial_len = 5
resid_len = 4
totres_len = 5
mdpoleto marked this conversation as resolved.
Show resolved Hide resolved

# Check for attributes, use defaults for missing ones
attrs = {}
Expand Down Expand Up @@ -241,7 +268,10 @@ def write(self, selection, frame=None):
if n_atoms > 99999:
crd.write(self.fmt['NUMATOMS_EXT'].format(n_atoms))
else:
crd.write(self.fmt['NUMATOMS'].format(n_atoms))
if crdext is True:
crd.write(self.fmt['NUMATOMS_EXT'].format(n_atoms))
else:
crd.write(self.fmt['NUMATOMS'].format(n_atoms))
mdpoleto marked this conversation as resolved.
Show resolved Hide resolved

# Write all atoms

Expand Down