You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/source/guessing.rst
+18-14Lines changed: 18 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,16 +33,16 @@ Topology attributes can be guessed at Universe creation by passing in topology a
33
33
u.atoms.bonds
34
34
35
35
36
-
In general, guessing at Universe creation works very similarly to guessing using the guess_TopologyAttrs interface documented below. The main difference is that passing guesser-specific keyword arguments such as ``fudge_factor`` and ``vdwradii`` into Universe creation is **now deprecated and will be removed in version 3.0**. Instead, we recommend specifying these arguments through an explicit call to the :ref:`guess_TopologyAttrs <guess-topologyAttrs>` method.
36
+
In general, guessing at Universe creation works very similarly to guessing using the guess_TopologyAttrs interface documented below. The main difference is that passing guesser-specific keyword arguments such as ``fudge_factor`` and ``vdwradii`` into Universe creation is **now deprecated and will be removed in version 3.0**. Instead, we recommend specifying these arguments through an explicit call to the :ref:`guess_TopologyAttrs method<guess-topologyAttrs>`.
37
37
38
38
.. _guess-topologyAttrs:
39
39
40
-
Guessing using the guess_TopologyAttrs interface
41
-
================================================
40
+
Guessing using the ``guess_TopologyAttrs()`` interface
Topology attributes can also be guessed after Universe creation using the :meth:`~MDAnalysis.core.universe.Universe.guess_TopologyAttrs` method. The ``to_guess``, ``force_guess``, and ``context`` keywords are used to specify which attributes to guess, which attributes to forcibly re-guess, and which guesser to use, respectively. These three keywords perform the same way here as they do in Universe creation.
43
+
Topology attributes can also be guessed after :class:`~MDAnalysis.core.universe.Universe` creation using the :meth:`~MDAnalysis.core.universe.Universe.guess_TopologyAttrs` method. The ``to_guess``, ``force_guess``, and ``context`` keywords are used to specify which attributes to guess, which attributes to forcibly re-guess, and which guesser to use, respectively. These three keywords perform the same way here as they do in Universe creation.
44
44
45
-
As with Universe creation, the :ref:`DefaultGuesser <default-guesser>` is used as the default ``context``. The following example demonstrates how to guess atom types and masses after Universe creation.
45
+
As with :class:`Universe` creation, the :ref:`DefaultGuesser <default-guesser>` is used as the default ``context``. The following example demonstrates how to guess atom types and masses after Universe creation.
46
46
47
47
.. ipython:: python
48
48
@@ -51,12 +51,12 @@ As with Universe creation, the :ref:`DefaultGuesser <default-guesser>` is used a
51
51
u.atoms.types
52
52
53
53
54
-
The context can be specified either using a string (e.g. ``"default"``) or an already created Guesser object. It may be convenient to pass in an already-created Guesser object if there are particular keywords you want to use in guessing methods, such as the ``fudge_factor``, ``vdwradii`` or ``lower_bound`` keywords for controlling bond guessing. However, if additional keyword arguments are passed into ``guess_TopologyAttrs``, they will **replace** any existing arguments inside the guesser.
54
+
The context can be specified either using a string (e.g., ``"default"``) or an already created *Guesser* object (which will have been derived from the base class :class:`~MDAnalysis.guesser.base.GuesserBase`). It may be convenient to pass in an already-created *Guesser* object (such as the :class:`~MDAnalysis.guesser.default_guesser.DefaultGuesser`) if there are particular keywords you want to use in guessing methods, such as the ``fudge_factor``, ``vdwradii`` or ``lower_bound`` keywords for controlling bond guessing. However, if additional keyword arguments are passed into ``guess_TopologyAttrs``, they will **replace** any existing arguments inside the guesser.
55
55
56
56
.. ipython:: python
57
57
58
58
from MDAnalysis.guesser import DefaultGuesser
59
-
from MDAnalysis.tests.datafiles importCONECT
59
+
from MDAnalysis.tests.datafiles importCONECT# example data file
60
60
61
61
u = mda.Universe(CONECT)
62
62
guesser = DefaultGuesser(u, fudge_factor=1.2)
@@ -77,7 +77,7 @@ MDAnalysis will preferentially read topology attributes from file instead of re-
77
77
78
78
.. note::
79
79
80
-
In cases where the attribute is only present for *some* atoms in the file (e.g. a patchy element column in a PDB), MDAnalysis will only guess the attribute for atoms where it is not present in the file.
80
+
In cases where the attribute is only present for *some* atoms in the file (e.g. a patchy element column in a PDB), MDAnalysis will only guess the attribute for atoms where it is not present in the file.
81
81
82
82
To force MDAnalysis to re-guess a TopologyAttr, pass in the attribute to the ``force_guess`` keyword. This will force MDAnalysis to guess the attribute even if it is present in the file.
83
83
@@ -93,7 +93,7 @@ Guessing bonds, angles, and torsions
93
93
94
94
Whereas most attributes are guessed at the atom, residue, or segment level, guessing topology objects such as bonds, angles, dihedrals and impropers behaves somewhat differently, and interacts with the ``force_guess`` keyword specially.
95
95
96
-
Specifically, if these connectivity attributes are guessed, they are by default guessed *additively*. Therefore, if bonds and other objects are guessed twice, the bonds of the second guess are added on. Below, we see the number of bonds increase when guessed again with a looser criteria.
96
+
Specifically, if these connectivity attributes are guessed, they are by default guessed **additively**. Therefore, if bonds and other objects are guessed twice, **the bonds of the second guess are added on.** Below, we see the number of bonds increase when guessed again with a looser criteria.
97
97
98
98
.. ipython:: python
99
99
@@ -105,23 +105,23 @@ Specifically, if these connectivity attributes are guessed, they are by default
105
105
print(len(u.bonds))
106
106
107
107
108
-
However, the number of bonds doesn't change when the bonds are guessed again with a stricter criteria -- no new bonds are found.
108
+
However, the **number of bonds doesn't change when the bonds are guessed again with stricter criteria** -- no new bonds are found (and also no bonds are removed either, even if they do not match the new criteria):
Moreover, bonds are unique, so if the bonds are guessed again with a same criteria, the guessed bonds doesn't change.
116
+
Moreover, bonds are unique, so if the bonds are guessed again with the same criteria, the guessed bonds don't change:
117
117
118
118
.. ipython:: python
119
119
120
120
u.guess_TopologyAttrs(to_guess=["bonds"], fudge_factor=0.5) # same
121
121
print(len(u.bonds))
122
122
123
123
124
-
However, if you want to forcibly overwrite all existing bonds, angles, dihedrals or impropers, you can pass the object to the ``force_guess`` keyword. This will remove all existing objects of that type before guessing. Below, we see the number of bonds has shrunk when guessed with stricter criteria.
124
+
However, if you want to forcibly overwrite all existing bonds, angles, dihedrals or impropers, you can pass the object to the ``force_guess`` keyword. This will **remove all existing objects of that type before guessing.** Below, we see the number of bonds has shrunk when guessed with stricter criteria:
125
125
126
126
.. ipython:: python
127
127
@@ -133,9 +133,13 @@ However, if you want to forcibly overwrite all existing bonds, angles, dihedrals
133
133
Order of guessing
134
134
-----------------
135
135
136
-
The order of the attributes guessed can matter in some cases. For example, bond guessing with the DefaultGuesser relies on looking up the vdW radii of the atoms involved by their atom ``type``. (**Note: this behaviour will likely change to looking up by element in version 3.0**). That means that for file formats where the atom ``type`` is not a valid element, the atom ``type`` must be forcefully re-guessed for bond-guessing to work.
136
+
The order of the attributes guessed can matter in some cases. For example, bond guessing with the :class:`~MDAnalysis.guesser.default_guesser.DefaultGuesser` relies on looking up the vdW radii of the atoms involved by their atom ``type``. That means that for file formats where the atom ``type`` is not a valid element, the atom ``type`` must be forcefully re-guessed for bond-guessing to work.
137
+
138
+
.. note::
139
+
140
+
The behaviour of looking up radii by *type* will likely change to looking up by *element* in version 3.0.
137
141
138
-
Therefore the following will not work due to the types encoded in the PSF file:
142
+
Therefore the following will not work (in MDAnalysis < 3.0) due to the types encoded in the PSF file:
0 commit comments