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

Issue 782 removeflags #2515

Merged
merged 11 commits into from
Feb 15, 2020
4 changes: 4 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ Changes
* Removed `MDAnalysis.migration` (Issue #2490, PR #2496)
* The fasta2select now always assumes that the gap character in a sequence
is "-" (Issue #2448, PR #2457)
* Removed core.flags. Default behaviour (eg pbc, units) now defaults to
the default setting of the flag before removal. If you were using flags
you will now have to supply the flag setting as keyword arguments to
function calls. (Issue #782)

Deprecations
* analysis.hbonds.HydrogenBondAnalysis is deprecated in 1.0 (remove in 2.0)
Expand Down
15 changes: 6 additions & 9 deletions package/MDAnalysis/analysis/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,6 @@ class Density(Grid):
- *density*: unit of the density if ``isDensity=True`` or ``None``
otherwise; the default is "Angstrom^{-3}" for densities
(meaning :math:`\text{Å}^{-3}`).

(Actually, the default unit is the value of
``MDAnalysis.core.flags['length_unit']``; in most
cases this is "Angstrom".)
metadata : dict
a user defined dictionary of arbitrary values associated with the
density; the class does not touch :attr:`Density.metadata` but
Expand Down Expand Up @@ -325,7 +321,7 @@ class Density(Grid):
"""

def __init__(self, *args, **kwargs):
length_unit = MDAnalysis.core.flags['length_unit']
length_unit = 'Angstrom'

parameters = kwargs.pop('parameters', {})
if len(args) > 0 and isinstance(args[0], string_types) or isinstance(kwargs.get('grid', None), string_types):
Expand Down Expand Up @@ -718,10 +714,11 @@ def density_from_Universe(universe, delta=1.0, atomselection='name OH2',
defined boxes
.. versionchanged:: 0.13.0
*update_selection* and *quiet* keywords added

.. deprecated:: 0.16
The keyword argument *quiet* is deprecated in favor of *verbose*.

.. versionchanged:: 0.21.0
time_unit and length_unit default to ps and Angstrom now flags have
been removed (same as previous flag defaults)
"""
u = universe

Expand Down Expand Up @@ -815,7 +812,7 @@ def current_coordinates():
metadata['n_frames'] = n_frames
metadata['totaltime'] = round(u.trajectory.n_frames * u.trajectory.dt, 3)
metadata['dt'] = u.trajectory.dt
metadata['time_unit'] = MDAnalysis.core.flags['time_unit']
metadata['time_unit'] = 'ps'
try:
metadata['trajectory_skip'] = u.trajectory.skip_timestep # frames
except AttributeError:
Expand All @@ -832,7 +829,7 @@ def current_coordinates():
parameters['isDensity'] = False # must override


g = Density(grid=grid, edges=edges, units={'length': MDAnalysis.core.flags['length_unit']},
g = Density(grid=grid, edges=edges, units={'length': 'Angstrom'},
parameters=parameters, metadata=metadata)
g.make_density()
logger.info("Density completed (initial density in Angstrom**-3)")
Expand Down
1 change: 0 additions & 1 deletion package/MDAnalysis/coordinates/DCD.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
import types
import warnings

from ..core import flags
from .. import units as mdaunits # use mdaunits instead of units to avoid a clash
from ..exceptions import NoDataError
from . import base, core
Expand Down
13 changes: 3 additions & 10 deletions package/MDAnalysis/coordinates/GRO.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@

from . import base
from .core import triclinic_box, triclinic_vectors
from ..core import flags
from ..exceptions import NoDataError
from ..lib import util

Expand Down Expand Up @@ -301,21 +300,17 @@ class GROWriter(base.WriterBase):
}
fmt['xyz_v'] = fmt['xyz'][:-1] + "{vel[0]:8.4f}{vel[1]:8.4f}{vel[2]:8.4f}\n"

def __init__(self, filename, convert_units=None, n_atoms=None, **kwargs):
def __init__(self, filename, convert_units=True, n_atoms=None, **kwargs):
"""Set up a GROWriter with a precision of 3 decimal places.

Parameters
-----------
filename : str
output filename

n_atoms : int (optional)
number of atoms

convert_units : str (optional)
units are converted to the MDAnalysis base format; ``None`` selects
the value of :data:`MDAnalysis.core.flags` ['convert_lengths']

convert_units : bool (optional)
units are converted to the MDAnalysis base format; [``True``]
reindex : bool (optional)
By default, all the atoms were reindexed to have a atom id starting
from 1. [``True``] However, this behaviour can be turned off by
Expand All @@ -342,8 +337,6 @@ def __init__(self, filename, convert_units=None, n_atoms=None, **kwargs):
self.n_atoms = n_atoms
self.reindex = kwargs.pop('reindex', True)

if convert_units is None:
convert_units = flags['convert_lengths']
self.convert_units = convert_units # convert length and time to base units

def write(self, obj):
Expand Down
7 changes: 3 additions & 4 deletions package/MDAnalysis/coordinates/LAMMPS.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@
import os
import numpy as np

from ..core import flags
from ..core.groups import requires
from ..lib import util, mdamath, distances
from ..lib.util import cached
Expand Down Expand Up @@ -254,18 +253,18 @@ class DATAWriter(base.WriterBase):
"""
format = 'DATA'

def __init__(self, filename, convert_units=None, **kwargs):
def __init__(self, filename, convert_units=True, **kwargs):
"""Set up a DATAWriter

Parameters
----------
filename : str
output filename
convert_units : bool, optional
units are converted to the MDAnalysis base format; [``True``]
"""
self.filename = util.filename(filename, ext='data')

if convert_units is None:
convert_units = flags['convert_lengths']
self.convert_units = convert_units

self.units = {'time': 'fs', 'length': 'Angstrom'}
Expand Down
8 changes: 2 additions & 6 deletions package/MDAnalysis/coordinates/MOL2.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
import numpy as np

from . import base
from ..core import flags
from ..lib import util


Expand Down Expand Up @@ -281,20 +280,17 @@ class MOL2Writer(base.WriterBase):
multiframe = True
units = {'time': None, 'length': 'Angstrom'}

def __init__(self, filename, n_atoms=None, convert_units=None):
def __init__(self, filename, n_atoms=None, convert_units=True):
"""Create a new MOL2Writer

Parameters
----------
filename: str
name of output file
convert_units: bool (optional)
units are converted to the MDAnalysis base format; ``None`` selects
the value of :data:`MDAnalysis.core.flags` ['convert_lengths']
units are converted to the MDAnalysis base format; [``True``]
"""
self.filename = filename
if convert_units is None:
convert_units = flags['convert_lengths']
self.convert_units = convert_units # convert length and time to base units

self.frames_written = 0
Expand Down
10 changes: 3 additions & 7 deletions package/MDAnalysis/coordinates/PDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@
import collections
import numpy as np

from ..core import flags
from ..lib import util
from . import base
from ..topology.core import guess_atom_element
Expand Down Expand Up @@ -542,7 +541,7 @@ class PDBWriter(base.WriterBase):

def __init__(self, filename, bonds="conect", n_atoms=None, start=0, step=1,
remarks="Created by PDBWriter",
convert_units=None, multiframe=None):
convert_units=True, multiframe=None):
"""Create a new PDBWriter

Parameters
Expand All @@ -559,9 +558,8 @@ def __init__(self, filename, bonds="conect", n_atoms=None, start=0, step=1,
any remarks from the trajectory that serves as input are
written to REMARK records with lines longer than :attr:`remark_max_length` (66
characters) being wrapped.
convert_units: str (optional)
units are converted to the MDAnalysis base format; ``None`` selects
the value of :data:`MDAnalysis.core.flags` ['convert_lengths']
convert_units: bool (optional)
units are converted to the MDAnalysis base format; [``True``]
bonds : {"conect", "all", None} (optional)
If set to "conect", then only write those bonds that were already
defined in an input PDB file as PDB CONECT_ record. If set to "all",
Expand All @@ -585,8 +583,6 @@ def __init__(self, filename, bonds="conect", n_atoms=None, start=0, step=1,
# - additional title keyword could contain line for TITLE

self.filename = filename
if convert_units is None:
convert_units = flags['convert_lengths']
# convert length and time to base units
self.convert_units = convert_units
self._multiframe = self.multiframe if multiframe is None else multiframe
Expand Down
9 changes: 3 additions & 6 deletions package/MDAnalysis/coordinates/PQR.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
import numpy as np
import warnings

from ..core import flags
from ..lib import util
from . import base

Expand Down Expand Up @@ -197,23 +196,21 @@ class PQRWriter(base.WriterBase):
" {pos[2]:-8.3f} {charge:-7.4f} {radius:6.4f}\n")
fmt_remark = "REMARK {0} {1}\n"

def __init__(self, filename, convert_units=None, **kwargs):
def __init__(self, filename, convert_units=True, **kwargs):
"""Set up a PQRWriter with full whitespace separation.

Parameters
----------
filename : str
output filename
convert_units: bool (optional)
units are converted to the MDAnalysis base format; [``True``]
remarks : str (optional)
remark lines (list of strings) or single string to be added to the
top of the PQR file
"""
self.filename = util.filename(filename, ext='pqr')

if convert_units is None:
convert_units = flags['convert_lengths']
self.convert_units = convert_units # convert length and time to base units

self.remarks = kwargs.pop('remarks', "PQR file written by MDAnalysis")

def write(self, selection, frame=None):
Expand Down
4 changes: 1 addition & 3 deletions package/MDAnalysis/coordinates/ParmEd.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,9 @@

from . import base
from ..topology.tables import SYMB2Z
from ..core import flags
from ..core.universe import Universe



class ParmEdReader(base.SingleFrameReaderBase):
"""Coordinate reader for ParmEd."""
format = 'PARMED'
Expand Down Expand Up @@ -339,4 +337,4 @@ def convert(self, obj):
if isinstance(p.type, clstype):
typelist.append(p.type)
p.type.list = typelist
return struct
return struct
9 changes: 2 additions & 7 deletions package/MDAnalysis/coordinates/TRJ.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@
import logging

import MDAnalysis
from ..core import flags
from . import base
from ..lib import util

Expand Down Expand Up @@ -776,9 +775,7 @@ class NCDFWriter(base.WriterBase):
dt : float (optional)
timestep
convert_units : bool (optional)
``True``: units are converted to the AMBER base format; ``None``
selects the value of :data:`MDAnalysis.core.flags`
['convert_lengths'] (see :ref:`flags-label`).
``True``: units are converted to the AMBER base format; [``True``]
velocities : bool (optional)
Write velocities into the trajectory [``False``]
forces : bool (optional)
Expand Down Expand Up @@ -864,14 +861,12 @@ def __init__(self,
step=1,
dt=1.0,
remarks=None,
convert_units=None,
convert_units=True,
**kwargs):
self.filename = filename
if n_atoms == 0:
raise ValueError("NCDFWriter: no atoms in output trajectory")
self.n_atoms = n_atoms
if convert_units is None:
convert_units = flags['convert_lengths']
# convert length and time to base units on the fly?
self.convert_units = convert_units

Expand Down
9 changes: 2 additions & 7 deletions package/MDAnalysis/coordinates/TRZ.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
import errno

from . import base
from ..core import flags
from ..lib import util
from ..lib.util import cached
from .core import triclinic_box, triclinic_vectors
Expand Down Expand Up @@ -447,7 +446,7 @@ class TRZWriter(base.WriterBase):

units = {'time': 'ps', 'length': 'nm', 'velocity': 'nm/ps'}

def __init__(self, filename, n_atoms, title='TRZ', convert_units=None):
def __init__(self, filename, n_atoms, title='TRZ', convert_units=True):
"""Create a TRZWriter

Parameters
Expand All @@ -460,9 +459,7 @@ def __init__(self, filename, n_atoms, title='TRZ', convert_units=None):
title of the trajectory; the title must be 80 characters or
shorter, a longer title raises a ValueError exception.
convert_units : bool (optional)
units are converted to the MDAnalysis base format; ``None`` selects
the value of :data:`MDAnalysis.core.flags` ['convert_lengths'].
(see :ref:`flags-label`)
units are converted to the MDAnalysis base format; [``True``]
"""
self.filename = filename
if n_atoms is None:
Expand All @@ -474,8 +471,6 @@ def __init__(self, filename, n_atoms, title='TRZ', convert_units=None):
if len(title) > 80:
raise ValueError("TRZWriter: 'title' must be 80 characters of shorter")

if convert_units is None:
convert_units = flags['convert_lengths']
self.convert_units = convert_units

self.trzfile = util.anyopen(self.filename, 'wb')
Expand Down
9 changes: 3 additions & 6 deletions package/MDAnalysis/coordinates/XYZ.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
logger = logging.getLogger('MDAnalysis.coordinates.XYZ')

from . import base
from ..core import flags
from ..lib import util
from ..lib.util import cached
from ..exceptions import NoDataError
Expand All @@ -118,7 +117,7 @@ class XYZWriter(base.WriterBase):
# these are assumed!
units = {'time': 'ps', 'length': 'Angstrom'}

def __init__(self, filename, n_atoms=None, atoms=None, convert_units=None,
def __init__(self, filename, n_atoms=None, atoms=None, convert_units=True,
remark=None, **kwargs):
"""Initialize the XYZ trajectory writer

Expand Down Expand Up @@ -148,10 +147,8 @@ def __init__(self, filename, n_atoms=None, atoms=None, convert_units=None,
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whilst convert_units wasn't part of the __init__ docstring originally, would it be worth adding it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is on the Writer, so this being true would convert inputs to the native units ... for xyz? I'm not sure if XYZ has a native unit? So I'm not going to break anything here, but I'm not sure I want to document the fact that this option exists?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XYZ units are generally in angstroms and that's how most visualization packages interpret them (VMD for example).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So MDA does seem to assume ps/Angstrom on read, and the default writer also assume those units on the conversion. I guess the only case I could think of where this might be useful, is if for some reason you created a Universe with non-base units, and then wanted to use the writer to have a non-ps/Angstrom write. With the removal of flags, I'm not sure how likely that would be to happen though...

self.filename = filename
self.n_atoms = n_atoms
if convert_units is not None:
self.convert_units = convert_units
else:
self.convert_units = flags['convert_lengths']
self.convert_units = convert_units

self.atomnames = self._get_atoms_elements_or_names(atoms)
default_remark = "Written by {0} (release {1})".format(
self.__class__.__name__, __version__)
Expand Down
Loading