Tidying Universe.__init__#2322
Conversation
|
@lilyminium I agree that universe creation is a messy process, and there's lots of confusing options! But I think that filenames (ie This then leaves passing the I'm not sure what the no arguments use case is, especially now we have the I really like the cleaner structure of class Universe
def __init__(self, args):
if filenames_given:
top = self._top_from_filenames(args)
elif streams_given:
top = self._top_from_streams(args)
elif Topology_given:
top = args
# at this point we've unified all the mess into a proper Topology object
self._generate_from_topology()
# mess of coordinates can also be hidden away before this too?
coordinates = figure_out_coordinates(args)
self.load_new(coordinates)So we hide the messiness of the different creation arguments, but we don't force a lot of different creation methods. In terms of docs, I get that the |
Codecov Report
@@ Coverage Diff @@
## develop #2322 +/- ##
==========================================
Coverage ? 90.56%
==========================================
Files ? 170
Lines ? 22925
Branches ? 2959
==========================================
Hits ? 20763
Misses ? 1566
Partials ? 596
Continue to review full report at Codecov.
|
richardjgowers
left a comment
There was a problem hiding this comment.
Looking good, few comments but I like how much easier Universe.__init__ is now
257da4e to
4f65b94
Compare
richardjgowers
left a comment
There was a problem hiding this comment.
Needs either mushing into gross py2 syntax or putting on ice for a little
package/MDAnalysis/core/universe.py
Outdated
| # managed attribute holding Reader | ||
| self._trajectory = None | ||
|
|
||
| def __init__(self, topology, *coordinates, all_coordinates=False, |
There was a problem hiding this comment.
So Python 2.7 doesn't support this syntax, which is why we have the fugly *args, **kwargs syntax. So if we want this merged before the Py3 switch, we can change this to args/kwargs (and lose readability for a while) else we can put this PR on ice for a while and merge it once we've dropped Py2.
There was a problem hiding this comment.
The only visible changes are to the more articulate argument documentation, so it's probably more efficient to just wait until Python 2 finally goes away. Same with #2333
|
In #2527 it came up that
is included. What was the rationale for explicitly forbidding For context: #2527 states that at the moment |
|
@orbeckst I think the signature&options and intent of I thought this PR had been merged already, oops. |
|
In this case Universe without args should raise an error — I assume that’s what’s happening in this PR (sorry, I’m lazily replying from mobile).
The other issue that I linked above could then be closed.
… Am 13.02.2020 um 05:25 schrieb Richard Gowers ***@***.***>:
@orbeckst I think the signature&options and intent of mda.Universe.empty() is so different than mda.Universe(file1, file2) that it should have a separate entry point. I think 90+% of people want mda.Universe(files) so that should be what people see. The power use of .empty() should be separate in a classmethod that has all pertinent documentation there.
I thought this PR had been merged already, oops.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
4f65b94 to
9250f31
Compare
|
I changed it so that >>> import MDAnalysis as mda
>>> u = mda.Universe()
>>> print(u)
<Universe with 0 atoms>
>>> u.residues
<ResidueGroup with 0 residues>
>>> u._topology
<MDAnalysis.core.topology.Topology object at 0x105fe0590> |
Thank you for the explanation, that helps a lot. So the Universe is more like a numpy array (unsurprisingly...) than a list. In this case I'll back-paddle on what I said before and change my opinion:
|
richardjgowers
left a comment
There was a problem hiding this comment.
Ok mushed the nice signatures into py2.7 friendly syntax, can't wait to change them back
Related to #2282
Fixes #2527
Changes made in this Pull Request:
Added class methods to Universe__init__by having explicit kw/args and moving the topology/coordinate sorting to external functionsAn empty universe can no longer be created withUniverse(). UseUniverse.empty()Universe()creates a universe with 0 atomslen(coordinates)==0, orall_coordinates==True) now raises a warningPR Checklist