Coordinate Transformations

The following utility functions provide mechanisms for spatial transformations for mbuild compounds:

mbuild.coordinate_transform.force_overlap(move_this, from_positions, to_positions, add_bond=True)[source]

Move a Compound such that a position overlaps with another.

Computes an affine transformation that maps the from_positions to the respective to_positions, and applies this transformation to the compound.

Parameters:
move_thismb.Compound

The Compound to be moved.

from_positionsnp.ndarray, shape=(n, 3), dtype=float

Original positions.

to_positionsnp.ndarray, shape=(n, 3), dtype=float

New positions.

add_bondbool, optional, default=True

If from_positions and to_positions are Ports, create a bond between the two anchor atoms.

mbuild.coordinate_transform.x_axis_transform(compound, new_origin=None, point_on_x_axis=None, point_on_xy_plane=None)[source]

Move a compound such that the x-axis lies on specified points.

Parameters:
compoundmb.Compound

The compound to move.

new_originmb.Compound or list-like of size 3, default=[0.0, 0.0, 0.0]

Where to place the new origin of the coordinate system.

point_on_x_axismb.Compound or list-like of size 3, default=[1, 0, 0]

A point on the new x-axis.

point_on_xy_planemb.Compound or list-like of size 3, default=[1, 0, 0]

A point on the new xy-plane.

mbuild.coordinate_transform.y_axis_transform(compound, new_origin=None, point_on_y_axis=None, point_on_xy_plane=None)[source]

Move a compound such that the y-axis lies on specified points.

Parameters:
compoundmb.Compound

The compound to move.

new_originmb.Compound or like-like of size 3, default=[0, 0, 0]

Where to place the new origin of the coordinate system.

point_on_y_axismb.Compound or list-like of size 3, default=[0, 1, 0]

A point on the new y-axis.

point_on_xy_planemb.Compound or list-like of size 3, default=[0, 1, 0]

A point on the new xy-plane.

mbuild.coordinate_transform.z_axis_transform(compound, new_origin=None, point_on_z_axis=None, point_on_zx_plane=None)[source]

Move a compound such that the z-axis lies on specified points.

Parameters:
compoundmb.Compound

The compound to move.

new_originmb.Compound or list-like of size 3, default=[0, 0, 0]

Where to place the new origin of the coordinate system.

point_on_z_axismb.Compound or list-like of size 3, default=[0, 0, 1]

A point on the new z-axis.

point_on_zx_planemb.Compound or list-like of size 3, default=[0, 0, 1]

A point on the new xz-plane.

mbuild.compound.Compound.translate(self, by)

Translate the Compound by a vector.

Parameters:
bynp.ndarray, shape=(3,), dtype=float
mbuild.compound.Compound.translate_to(self, pos)

Translate the Compound to a specific position.

Parameters:
posnp.ndarray, shape=3(,), dtype=float
mbuild.compound.Compound.rotate(self, theta, around)

Rotate Compound around an arbitrary vector.

Parameters:
thetafloat

The angle by which to rotate the Compound, in radians.

aroundnp.ndarray, shape=(3,), dtype=float

The vector about which to rotate the Compound.

mbuild.compound.Compound.spin(self, theta, around, anchor=None)

Rotate Compound in place around an arbitrary vector.

Parameters:
thetafloat

The angle by which to rotate the Compound, in radians.

aroundnp.ndarray, shape=(3,), dtype=float

The axis about which to spin the Compound.

anchormb.Compound, optional, default=None (self)

Anchor compound/particle to perform spinning. If the anchor is not a particle, the spin will be around the center of the anchor Compound.