Skip to content

Commit 101008b

Browse files
lilyminiumIAlibay
andauthored
Update guesser docs (#4743)
* update docs * i've forgotten how sphinx works * replace ref with class * update changelog * fix whitespace * Update default_guesser.py Co-authored-by: Irfan Alibay <IAlibay@users.noreply.github.com> --------- Co-authored-by: Irfan Alibay <IAlibay@users.noreply.github.com>
1 parent 9b69745 commit 101008b

19 files changed

+252
-35
lines changed

package/CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ The rules for this file:
2323
* 2.8.0
2424

2525
Fixes
26+
* Adds guessed attributes documentation back to each parser page
27+
and updates overall guesser docs (Issue #4696)
2628
* Fix Bohrium (Bh) atomic mass in tables.py (PR #3753)
2729
* set `n_parts` to the total number of frames being analyzed if
2830
`n_parts` is bigger. (Issue #4685)

package/MDAnalysis/guesser/default_guesser.py

Lines changed: 114 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,70 @@
2727
2828
DefaultGuesser is a generic guesser class that has basic guessing methods.
2929
This class is a general purpose guesser that can be used with most topologies,
30-
but being generic makes it the less accurate among all guessers.
30+
but being generic makes it the least accurate among all guessers.
3131
3232
33+
Guessing behavior
34+
-----------------
35+
36+
This section describes how each attribute is guessed by the DefaultGuesser.
37+
38+
Masses
39+
~~~~~~
40+
41+
We first attempt to look up the mass of an atom based on its element if the
42+
element TopologyAttr is available. If not, we attempt to lookup the mass based
43+
on the atom type (``type``) TopologyAttr. If neither of these is available, we
44+
attempt to guess the atom type based on the atom name (``name``) and then
45+
lookup the mass based on the guessed atom type.
46+
47+
48+
Types
49+
~~~~~
50+
51+
We attempt to guess the atom type based on the atom name (``name``).
52+
The name is first stripped of any numbers and symbols, and then looked up in
53+
the :data:`MDAnalysis.guesser.tables.atomelements` table. If the name is not
54+
found, we continue checking variations of the name following the logic in
55+
:meth:`DefaultGuesser.guess_atom_element`. Ultimately, if no match is found,
56+
the first character of the stripped name is returned.
57+
58+
Elements
59+
~~~~~~~~
60+
61+
This follows the same method as guessing atom types.
62+
63+
64+
Bonds
65+
~~~~~
66+
67+
Bonds are guessed based on the distance between atoms.
68+
See :meth:`DefaultGuesser.guess_bonds` for more details.
69+
70+
Angles
71+
~~~~~~
72+
73+
Angles are guessed based on the bonds between atoms.
74+
See :meth:`DefaultGuesser.guess_angles` for more details.
75+
76+
Dihedrals
77+
~~~~~~~~~
78+
79+
Dihedrals are guessed based on the angles between atoms.
80+
See :meth:`DefaultGuesser.guess_dihedrals` for more details.
81+
82+
Improper Dihedrals
83+
~~~~~~~~~~~~~~~~~~
84+
85+
Improper dihedrals are guessed based on the angles between atoms.
86+
See :meth:`DefaultGuesser.guess_improper_dihedrals` for more details.
87+
88+
Aromaticities
89+
~~~~~~~~~~~~~
90+
91+
Aromaticity is guessed using RDKit's GetIsAromatic method.
92+
See :meth:`DefaultGuesser.guess_aromaticities` for more details.
93+
3394
3495
3596
@@ -70,6 +131,23 @@ class DefaultGuesser(GuesserBase):
70131
You can use this guesser either directly through an instance, or through
71132
the :meth:`~MDAnalysis.core.universe.Universe.guess_TopologyAttrs` method.
72133
134+
Parameters
135+
----------
136+
universe : Universe
137+
The Universe to apply the guesser on
138+
box : np.ndarray, optional
139+
The box of the Universe. This is used for bond guessing.
140+
vdwradii : dict, optional
141+
Dict relating atom types: vdw radii. This is used for bond guessing
142+
fudge_factor : float, optional
143+
The factor by which atoms must overlap each other to be considered
144+
a bond. Larger values will increase the number of bonds found. [0.55]
145+
lower_bound : float, optional
146+
The minimum bond length. All bonds found shorter than this length
147+
will be ignored. This is useful for parsing PDB with altloc records
148+
where atoms with altloc A and B may be very close together and
149+
there should be no chemical bond between them. [0.1]
150+
73151
Examples
74152
--------
75153
to guess bonds for a universe::
@@ -84,8 +162,23 @@ class DefaultGuesser(GuesserBase):
84162
"""
85163
context = 'default'
86164

87-
def __init__(self, universe, **kwargs):
88-
super().__init__(universe, **kwargs)
165+
def __init__(
166+
self,
167+
universe,
168+
box=None,
169+
vdwradii=None,
170+
fudge_factor=0.55,
171+
lower_bound=0.1,
172+
**kwargs
173+
):
174+
super().__init__(
175+
universe,
176+
box=box,
177+
vdwradii=vdwradii,
178+
fudge_factor=fudge_factor,
179+
lower_bound=lower_bound,
180+
**kwargs
181+
)
89182
self._guesser_methods = {
90183
'masses': self.guess_masses,
91184
'types': self.guess_types,
@@ -212,8 +305,19 @@ def guess_types(self, atom_types=None, indices_to_guess=None):
212305
def guess_atom_element(self, atomname):
213306
"""Guess the element of the atom from the name.
214307
215-
Looks in dict to see if element is found, otherwise it uses the first
216-
character in the atomname. The table comes from CHARMM and AMBER atom
308+
First all numbers and symbols are stripped from the name.
309+
Then the name is looked up in the
310+
:data:`MDAnalysis.guesser.tables.atomelements` table.
311+
If the name is not found, we remove the last character or
312+
first character from the name and check the table for both,
313+
with a preference for removing the last character. If the name is
314+
still not found, we iteratively continue to remove the last character
315+
or first character until we find a match. If ultimately no match
316+
is found, the first character of the stripped name is returned.
317+
318+
If the input name is an empty string, an empty string is returned.
319+
320+
The table comes from CHARMM and AMBER atom
217321
types, where the first character is not sufficient to determine the
218322
atom type. Some GROMOS ions have also been added.
219323
@@ -270,26 +374,11 @@ def guess_bonds(self, atoms=None, coords=None):
270374
271375
Parameters
272376
----------
273-
atoms : AtomGroup
274-
atoms for which bonds should be guessed
275-
fudge_factor : float, optional
276-
The factor by which atoms must overlap eachother to be considered a
277-
bond. Larger values will increase the number of bonds found. [0.55]
278-
vdwradii : dict, optional
279-
To supply custom vdwradii for atoms in the algorithm. Must be a
280-
dict of format {type:radii}. The default table of van der Waals
281-
radii is hard-coded as :data:`MDAnalysis.guesser.tables.vdwradii`.
282-
Any user defined vdwradii passed as an argument will supercede the
283-
table values. [``None``]
284-
lower_bound : float, optional
285-
The minimum bond length. All bonds found shorter than this length
286-
will be ignored. This is useful for parsing PDB with altloc records
287-
where atoms with altloc A and B maybe very close together and
288-
there should be no chemical bond between them. [0.1]
289-
box : array_like, optional
290-
Bonds are found using a distance search, if unit cell information
291-
is given, periodic boundary conditions will be considered in the
292-
distance search. [``None``]
377+
atoms: AtomGroup
378+
atoms for which bonds should be guessed
379+
coords: np.ndarray, optional
380+
coordinates of the atoms. If not provided, the coordinates
381+
of the ``atoms`` in the universe are used.
293382
294383
Returns
295384
-------

package/MDAnalysis/topology/CRDParser.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
Residues are detected through a change is either resid or resname
3434
while segments are detected according to changes in segid.
3535
36+
.. note::
37+
38+
By default, atomtypes and masses will be guessed on Universe creation.
39+
This may change in release 3.0.
40+
See :ref:`Guessers` for more information.
41+
3642
.. _CRD: https://www.charmmtutorial.org/index.php/CHARMM:The_Basics
3743
3844
@@ -72,6 +78,13 @@ class CRDParser(TopologyReaderBase):
7278
- Resnums
7379
- Segids
7480
81+
82+
.. note::
83+
84+
By default, atomtypes and masses will be guessed on Universe creation.
85+
This may change in release 3.0.
86+
See :ref:`Guessers` for more information.
87+
7588
.. versionchanged:: 2.8.0
7689
Type and mass are not longer guessed here. Until 3.0 these will still be
7790
set by default through through universe.guess_TopologyAttrs() API.

package/MDAnalysis/topology/DLPolyParser.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
- Atomnames
3131
- Atomids
3232
33+
.. note::
34+
35+
By default, atomtypes and masses will be guessed on Universe creation.
36+
This may change in release 3.0.
37+
See :ref:`Guessers` for more information.
38+
3339
.. _Poly: http://www.stfc.ac.uk/SCD/research/app/ccg/software/DL_POLY/44516.aspx
3440
3541
Classes

package/MDAnalysis/topology/DMSParser.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,17 @@ class DMSParser(TopologyReaderBase):
8686
Segment:
8787
- Segids
8888
89+
.. note::
90+
91+
By default, atomtypes will be guessed on Universe creation.
92+
This may change in release 3.0.
93+
See :ref:`Guessers` for more information.
94+
8995
.. _DESRES: http://www.deshawresearch.com
9096
.. _Desmond: http://www.deshawresearch.com/resources_desmond.html
9197
.. _DMS: http://www.deshawresearch.com/Desmond_Users_Guide-0.7.pdf
9298
.. versionchanged:: 2.8.0
93-
Removed type and mass guessing (attributes guessing takes place now
99+
Removed type guessing (attributes guessing takes place now
94100
through universe.guess_TopologyAttrs() API).
95101
96102
"""

package/MDAnalysis/topology/ExtendedPDBParser.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ class ExtendedPDBParser(PDBParser.PDBParser):
7878
- bonds
7979
- formalcharges
8080
81+
.. note::
82+
83+
By default, atomtypes and masses will be guessed on Universe creation.
84+
This may change in release 3.0.
85+
See :ref:`Guessers` for more information.
86+
8187
8288
See Also
8389
--------

package/MDAnalysis/topology/FHIAIMSParser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ class FHIAIMSParser(TopologyReaderBase):
6666
Creates the following attributes:
6767
- Atomnames
6868
69+
70+
.. note::
71+
72+
By default, atomtypes and masses will be guessed on Universe creation.
73+
This may change in release 3.0.
74+
See :ref:`Guessers` for more information.
75+
6976
.. versionchanged:: 2.8.0
7077
Removed type and mass guessing (attributes guessing takes place now
7178
through universe.guess_TopologyAttrs() API).

package/MDAnalysis/topology/GMSParser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ class GMSParser(TopologyReaderBase):
7373
- names
7474
- atomic charges
7575
76+
77+
.. note::
78+
79+
By default, atomtypes and masses will be guessed on Universe creation.
80+
This may change in release 3.0.
81+
See :ref:`Guessers` for more information.
82+
7683
.. versionadded:: 0.9.1
7784
.. versionchanged:: 2.8.0
7885
Removed type and mass guessing (attributes guessing takes place now

package/MDAnalysis/topology/GROParser.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ class GROParser(TopologyReaderBase):
6767
- atomids
6868
- atomnames
6969
70+
.. note::
71+
72+
By default, atomtypes and masses will be guessed on Universe creation.
73+
This may change in release 3.0.
74+
See :ref:`Guessers` for more information.
75+
7076
.. versionchanged:: 2.8.0
7177
Removed type and mass guessing (attributes guessing takes place now
7278
through universe.guess_TopologyAttrs() API).

package/MDAnalysis/topology/ITPParser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,13 @@ class ITPParser(TopologyReaderBase):
473473
.. _ITP: http://manual.gromacs.org/current/reference-manual/topologies/topology-file-formats.html#molecule-itp-file
474474
.. _TOP: http://manual.gromacs.org/current/reference-manual/file-formats.html#top
475475
476+
.. note::
477+
478+
By default, atomtypes and masses will be guessed on Universe creation
479+
if they are not read from the input file.
480+
This may change in release 3.0.
481+
See :ref:`Guessers` for more information.
482+
476483
.. versionchanged:: 2.2.0
477484
no longer adds angles for water molecules with SETTLE constraint
478485
.. versionchanged:: 2.8.0

0 commit comments

Comments
 (0)