mooonpy.molspace.atoms module

This module provides a class to organize atoms information

class mooonpy.molspace.atoms.Atoms(astyles, **kwargs)[source]

Bases: dict

COM(masses, atom_ids='all') Tuple[float, float, float][source]

Mass-weighted center of mass of the selected atoms.

Parameters:
  • masses – A {type: mass} dict. Pass either a plain dict or mol.ff.masses (the Parameters object’s coeffs[0] is unwrapped automatically).

  • atom_ids'all' or an iterable of atom ids.

Returns:

(x, y, z) center of mass.

Raises:

KeyError – If a selected atom’s type is not in masses.

centroid(atom_ids='all') Tuple[float, float, float][source]

Unweighted centroid of the selected atoms.

Parameters:

atom_ids'all' or an iterable of atom ids.

Returns:

(x, y, z) centroid.

copy(deepcopy=False)[source]

Return a fully independent copy of this Atoms container (independence verified in tests/test_molspace_copy.py).

The Atom factory class and defaults are frozen, so the copy references the SAME factory and read-only styles instance by design; atom instances and box are rebuilt fresh.

Parameters:

deepcopy – if True, use the copy.deepcopy fallback (same result, ~5x slower; for cross-checking only).

move(vect=None, mode='offset', atom_ids='all')[source]

Translate or scale atom coordinates in place.

Parameters:
  • vect (tuple[float, float, float] or None) – Displacement / target / scale vector. None is a no-op.

  • mode

    How vect is interpreted:

    • 'offset' — add vect to each atom’s coordinates.

    • 'centroid' — shift the selection so its centroid lands at vect (computed via centroid()).

    • 'scale' — multiply each coordinate component by vect. This also scales the simulation Box parameters about the origin (xlo *= vx etc., tilt factors scale with the relevant axis).

  • atom_ids'all' or an iterable of atom ids to apply the move to. 'scale' always scales the box regardless of the selection.

For mass-weighted re-centering, compute the COM externally with COM() and pass the desired delta with mode='offset'.

shift(sx=0, sy=0, sz=0)[source]
shrinkwrap(pad=0.0)[source]

Resize box to tightly enclose every atom, with optional padding on each face.

Parameters:

pad (float) – Distance (Å) added to each face beyond the atom extent.

Raises:

ValueError – If the box is triclinic (any of xy/xz/yz is nonzero); shrinkwrap on tilted boxes is ill-defined here.

wrap()[source]

Wrap all coordinates so all atoms are inside the box, and indexes box image appropriately.

See also

box.get_transformation_matrix, box.pos2frac, box.frac2pos

..TODO::

This should work for triclinic, but is currently untested