6. Guesser modules
This module contains the context-aware guessers, which are used by the guess_TopologyAttrs()
API. Context-aware guessers’ main purpose
is to be tailored guesser classes that target specific file format or force field (eg. PDB file format, or Martini forcefield).
Having such guessers makes attribute guessing more accurate and reliable than having generic guessing methods that don’t fit all scenarios.
6.1. Example uses of guessers
6.1.1. Default behavior
By default, MDAnalysis will guess the “mass” and “type” (atom type) attributes for all particles in the Universe
using the DefaultGuesser
at the time of Universe creation,
if they are not read from the input file. If the required information is not present in the input file,
a warning will be raised.
Please see the DefaultGuesser
for more information.
6.1.2. Guessing using guess_TopologyAttrs()
API
Guessing can be done through the Universe’s guess_TopologyAttrs()
as following:
import MDAnalysis as mda
from MDAnalysisTests.datafiles import PDB
u = mda.Universe(PDB)
print(hasattr(u.atoms, 'elements')) # returns False
u.guess_TopologyAttrs(to_guess=['elements'])
print(u.atoms.elements) # print ['N' 'H' 'H' ... 'NA' 'NA' 'NA']
In the above example, we passed elements
as the attribute we want to guess
guess_TopologyAttrs()
guess then add it as a topology
attribute to the AtomGroup
of the universe.
If the attribute already exists in the universe, passing the attribute of interest to the to_guess
parameter will only fill the empty values of the attribute if any exists.
To override all the attribute values, you can pass the attribute to the force_guess
parameter instead of to_guess
as following:
import MDAnalysis as mda
from MDAnalysisTests.datafiles import PRM12
u = mda.Universe(PRM12, context='default', to_guess=()) # types ['HW', 'OW', ..]
u.guess_TopologyAttrs(force_guess=['types']) # types ['H', 'O', ..]
Note
The default context
will use the DefaultGuesser
Available guessers
Guesser core modules
The remaining pages are primarily of interest to developers as they contain functions and classes that are used in the implementation of the context-specific guessers.