Skip to content

MDAnalysis 0.11 unifying release user guide

Tyler Reddy edited this page Aug 14, 2015 · 29 revisions

MDAnalysis 0.11.0 is a substantial release that unifies much of the code base at the cost of some necessary changes to the user API. The key points for adjusting your code accordingly are outlined below. The details are in the Release Notes for 0.11.0.

Note that we also plan to have a conversion script ten2eleven.py available (see #377) that should do some of the necessary changes.

How to change your code

Removed contact matrix progress meter

The MDAnalysis.analysis.distances.contact_matrix function does not show progress anymore. Remove the keywords progress_meter_freq and suppress_progmet from your code:

import MDAnalysis
import MDAnalysis.analysis.distances
import numpy as np
#300 rows of random xyz array data, to simulate coordinates:
random_array_coords = np.float32(np.random.rand(300,3)) 

#before 0.11 release:
#contact_matrix = MDAnalysis.analysis.distances.contact_matrix(random_array_coords, returntype = "sparse", progress_meter_freq=10, suppress_progmet=True) 
#after 0.11 release:
contact_matrix = MDAnalysis.analysis.distances.contact_matrix(random_array_coords, returntype = "sparse") 

New Timestep behaviour

Previously, Timesteps could be initiated with either

  • integer (allocated to this size)
  • another Timestep (copied it)
  • coordinates (created a Timestep of this size and filled it)

Now Timesteps can only be initiated with an integer argument.

To create a Timestep from another Timestep, or from an array of coordinates, use the new from_timestep and from_coordinates class methods:

from MDAnalysis.coordinates.base import Timestep

ts = Timestep(10)
ts = Timestep.from_timestep(other_ts)
ts = Timestep.from_coordinates(coordinates)
# with optional velocities and/or forces
ts = Timestep.from_coordinates(coordinates, velocities=velocities, forces=forces)

atomgroup methods to properties and select_atoms replacing selectAtoms

import MDAnalysis
from MDAnalysis.tests.datafiles import GRO, XTC
universe = MDAnalysis.Universe(GRO, XTC)

#before 0.11
#all_selection = universe.selectAtoms('all')
#after 0.11
all_selection = universe.select_atoms('all')

#before 0.11:
#all_selection.residues()
#after 0.11:
all_selection.residues

#before 0.11:
#all_selection.charges()
#after 0.11:
all_selection.charges

Atom.number renamed to Atom.index

import MDAnalysis
from MDAnalysis.tests.datafiles import GRO, XTC
universe = MDAnalysis.Universe(GRO, XTC)

atomgroup = universe.select_atoms('all')
first_atom = atomgroup[0]

#before 0.11:
#first_atom.number
#after 0.11:
first_atom.index

Migration of some code to MDAnalysis.lib

import MDAnalysis
import numpy

random_coord_array_1 = numpy.float32(numpy.random.rand(20,3))
random_coord_array_2 = numpy.float32(numpy.random.rand(20,3))

#before 0.11:
#import MDAnalysis.core.distances
#distance_array = MDAnalysis.core.distances.distance_array(random_coord_array_1, random_coord_array_2)
#after 0.11: 
import MDAnalysis.lib.distances
distance_array = MDAnalysis.lib.distances.distance_array(random_coord_array_1, random_coord_array_2)

Timestep._x _y and _z are now read only

The fullgroup selection keyword is now deprecated

0.11 introduces the global selection modifier keyword, which, among other cases, can be used to replace fullgroup when combined with group. You need only change fullgroup to global group in your selections:

#before 0.11:
solvent = universe.selectAtoms("name SOL")
solvating = solvent.selectAtoms("around 5 fullgroup ref", ref=some_complex_selection)
#after 0.11: 
solvent = universe.select_atoms("name SOL")
solvating = solvent.select_atoms("around 5 global group ref", ref=some_complex_selection)

numberOfAtoms() to n_atoms and others

import MDAnalysis
from MDAnalysis.tests.datafiles import GRO, XTC
universe = MDAnalysis.Universe(GRO, XTC)
all_selection = universe.select_atoms('all')

#before 0.11:
#atom_count = all_selection.numberOfAtoms()
#after 0.11:
atom_count = all_selection.n_atoms

#before 0.11:
#residue_count = all_selection.numberOfResidues()
#after 0.11:
residue_count = all_selection.n_residues

#before 0.11:
#segment_count = all_selection.numberOfSegments()
#after 0.11:
segment_count = all_selection.n_segments

#before 0.11:
#frame_count = universe.trajectory.numframes
#after 0.11:
frame_count = universe.trajectory.n_frames

Renamed topology methods

Frame numbering is now 0-based

import MDAnalysis
from MDAnalysis.tests.datafiles import GRO, XTC
universe = MDAnalysis.Universe(GRO, XTC)

#before 0.11:
if 1 == universe.trajectory.frame:
    print 'currently on first frame'

#after 0.11:
if 0 == universe.trajectory.frame:
    print 'currently on first frame'
Clone this wiki locally