Repository navigation
Create a Grid from a native mrcfile object - #186
Open
aviralgarg05 wants to merge 1 commit into
Open
aviralgarg05 wants to merge 1 commit into
aviralgarg05 wants to merge 1 commit into
Conversation
Grid(grid=...) now also accepts the native objects of the mrcfile
library, i.e., anything derived from mrcfile.mrcobject.MrcObject, which
covers MrcFile, MrcInterpreter and subclasses such as MrcMemmap and
GzipMrcFile:
with mrcfile.open("density.mrc") as mrcobj:
g = Grid(mrcobj)
Pulling the data, header, origin and grid spacing out of an mrcfile
object is exactly what reading a file already did, so that part was
split out of MRC.read() into MRC._populate() and is now shared with the
new classmethod MRC.from_mrcfile(). The grid data are a view of the data
of the native object and are not copied, so a grid built this way needs
the native object to keep its data around.
The API interoperability docs still said that loading from a native
object was not implemented; they now describe it for both MRC and
OpenVDB.
Fixes MDAnalysis#172
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #186 +/- ##
==========================================
+ Coverage 90.35% 90.53% +0.18%
==========================================
Files 6 6
Lines 985 1004 +19
Branches 131 133 +2
==========================================
+ Hits 890 909 +19
Misses 57 57
Partials 38 38 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Documentation build overview
7 files changed ·
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #172
Grid()now takes a native mrcfile object, not just a filename:The check is against
mrcfile.mrcobject.MrcObject, soMrcFileandMrcInterpreterboth work, and so do subclasses likeMrcMemmapandGzipMrcFile.Getting the data, header, origin and spacing out of an mrcfile object is
what reading a file already did, so I pulled that out of
MRC.read()into
MRC._populate()and share it with a new classmethodMRC.from_mrcfile(). That keeps the MRC-specific code inmrc.pyandleaves
core.Gridwith just the dispatch, along the lines of #162. Mostof the diff in
mrc.pyis that block moving one level out.As discussed in the issue, the data are a view and are not copied. The
one caveat worth knowing is that a grid built from a memory-mapped
object loses its data when that object is closed; it is noted in the
docstring.
The interoperability docs still said loading from a native object was
not implemented, so I updated that section. It covers OpenVDB too, since
#170 landed that half already.
Tested with
MrcFile,MrcMemmap, a gzipped file,MrcInterpreter,and an object built in memory with no file behind it, plus the
non-volumetric,
assume_volumetricand triclinic paths. A DX fileexported from a grid built this way is byte-identical to one exported
from the same file read from disk. Docs build clean.