wcenter
- mdtools.structure.wcenter(ag, weights=None, pbc=False, cmp='group', make_whole=False, debug=False)[source]
Calculate the weighted center of (compounds of) an MDAnalysis
AtomGroup.- Parameters:
ag (
MDAnalysis.core.groups.AtomGroup) – The MDAnalysisAtomGroupfor which to calculate the weighted center.weights (
array_likeorNone, optional) – Weights to be used, given as a 1d array containing the weights for eachAtomin ag. Weights are mapped toAtomsby the order they appear in ag. Setting weights toNoneis equivalent to passing identical weights for allAtomsin ag and therefore this is equivalent to calculating the center of geometry. If the weights of a compound sum up to zero, the coordinates of that compound’s weighted center will benan.pbc (
bool, optional) – IfTrueand cmp is'group', move allAtomsin ag to the primary unit cell before calculating the weighted center. IfTrueand cmp is not'group', the weighted center of each compound will be calculated without moving anyAtomsto keep the compounds intact (if they were intact before). Instead, the resulting position vectors will be moved to the primary unit cell after calculating the weighted center.cmp (
{'group', 'segments', 'residues', 'molecules', 'fragments', 'atoms'}, optional) – The compounds of ag for which to calculate the weighted center. If'group', the weighted center of allAtomsin ag will be returned as a single position vector. If'atoms', simply the positions of all atoms in ag will be returned (2d array). Else, the weighted center of eachSegment,Residue, molecule, orfragmentcontained in ag will be returned as an array of position vectors, i.e. a 2d array. Refer to the MDAnalysis’ user guide for an explanation of these terms. Note that in any case, also if cmp is e.g.'residues', only theAtomsbelonging to ag are taken into account, even if the compound might comprise additionalAtomsthat are not contained in ag.make_whole (
bool, optional) – IfTrue, compounds whose bonds are split across periodic boundaries are made whole before calculating their center. Note that allAtomsin ag are wrapped back into the primary unit cell before making compounds whole to ensure that the algorithm is working properly. This means that making compounds whole in an unwrapped trajectory will lead to a wrapped trajectory with whole compounds (someAtomsmay lie outside the primary unit cell, but each compound’s center will lie inside the primary unit cell). Note that make_whole has no effect if cmp is set to'atoms'.debug (
bool, optional) – IfTrue, run in debug mode.
- Returns:
centers (
numpy.ndarray) – Position of the weighted center of each compound in ag. If cmp was set to'group', the output will be a single position vector of shape(3,). Else, the output will be a 2d array of shape(n, 3)wherenis the number of compounds in ag.- Raises:
RuntimeWarning : – If debug is
Trueand the weighted center of any compound isnan.
See also
MDAnalysis.core.groups.AtomGroup.center()Weighted center of (compounds of) the group
MDAnalysis.core.groups.AtomGroup.center_of_geometry()Center of geometry of (compounds of) the group
MDAnalysis.core.groups.AtomGroup.center_of_mass()Center of mass of (compounds of) the group
mdtools.structure.center()Different types of centers of (compounds of) an MDAnalysis
AtomGroupmdtools.structure.wcenter_pos()Calculate the weighted center of a position array
mdtools.structure.coc()Center of charge of (compounds of) an MDAnalysis
AtomGroupmdtools.structure.cog()Center of geometry of (compounds of) an MDAnalysis
AtomGroupmdtools.structure.com()Center of mass of (compounds of) an MDAnalysis
AtomGroup
Notes
This function uses the
center()method of the inputAtomGroupto calculate the weighted center.Important
If the weights of a compound sum up to zero, the coordinates of that compound’s weighted center will be
nan! If debug is set toTrue, a warning will be raised if any compound’s weighted center isnan.If make_whole is
True, allAtomsin ag are wrapped back into the primary unit cell usingmdtools.box.wrap()before callingcenter()with the option unwrap set toTrue. This is done to ensure that the unwrap algorithm (better called “make whole” algorithm) ofcenter()is working properly. This means that making compounds whole in an unwrapped trajectory will lead to a wrapped trajectory with whole compounds (someAtomsmay lie outside the primary unit cell, but each compound’s center will lie inside the primary unit cell). make_whole has no effect if cmp is set to'atoms'.