FixAtomConstraints

class FixAtomConstraints(atom_selection, fix_cartesian_direction=None)

This constraint fixes the positions of the selected atoms during a MolecularDynamics() or OptimizeGeometry() simulation.

Parameters:
  • atom_selection (list of ints) – The list of indices of the atoms whose positions should be fixed.

  • fix_cartesian_direction (list(3) of bools) – List of three directions to constrain the group of atoms in. If the Bravais lattice does not change (or a MoleculeConfiguration is used) then the three flags correspond to constraining the x, y, and z Cartesian coordinates. If the Bravais lattice does change, then the three flags correspond to constraining the fractional coordinates along the a, b, and c axes.
    Default: [True, True, True]

atomIndices()
Returns:

The indices of the fixed atoms.

Return type:

list ints

frozenDegreesOfFreedom(local_atoms=None)
Parameters:

local_atoms (list of int | None) – The group of atoms from which the frozen degrees of freedom should be calculated, e.g. a thermalized group of atoms.
Default: All atoms.

Returns:

The number of degrees of freedom that are frozen by the constraints.

Return type:

int

uniqueString()

Return a unique string representing the state of the object.

Usage Examples

Run an MD simulation of a decane molecule with one end of the molecule fixed.

# Define elements
elements = [Hydrogen, Carbon, Hydrogen, Hydrogen, Carbon, Hydrogen, Hydrogen,
            Carbon, Hydrogen, Hydrogen, Carbon, Hydrogen, Hydrogen, Carbon,
            Hydrogen, Hydrogen, Carbon, Hydrogen, Hydrogen, Carbon, Hydrogen,
            Hydrogen, Carbon, Hydrogen, Hydrogen, Carbon, Hydrogen, Hydrogen,
            Carbon, Hydrogen, Hydrogen, Hydrogen]

# Define coordinates
cartesian_coordinates = [[ 2.949218676646,  0.371893089344, -5.977841255567],
                         [ 2.0915751053  ,  0.325878896596, -5.255719576195],
                         [ 1.450283574002,  1.214213807408, -5.492967455154],
                         [ 1.451118166918, -0.526603584715, -5.601873618684],
                         [ 1.822966280268,  0.248365819288, -4.006203357873],
                         [ 2.452472374579, -0.657496389029, -3.794106921656],
                         [ 2.454588788042,  1.119399272419, -3.683412523973],
                         [ 1.11002977129 ,  0.182932682631, -2.941890060606],
                         [ 0.514074186602,  1.11809089051 , -3.137372769128],
                         [ 0.511494198217, -0.719003710087, -3.252072509036],
                         [ 0.842624096707,  0.10516011283 , -1.690762149425],
                         [ 1.491345296758, -0.78355395752 , -1.471599662887],
                         [ 1.494967653129,  0.95670152228 , -1.362236499313],
                         [ 0.132859680402,  0.039658959846, -0.626048074315],
                         [-0.482794358104,  0.9589027956  , -0.827177016793],
                         [-0.487026068393, -0.844146311539, -0.940982573926],
                         [-0.132380369437, -0.038781999777,  0.626344899449],
                         [ 0.483113914589, -0.95814352964 ,  0.827391526337],
                         [ 0.487761818334,  0.84474606991 ,  0.941323554846],
                         [-0.842177289594, -0.104271778821,  1.690893077731],
                         [-1.490395532317,  0.784892174015,  1.472217773116],
                         [-1.494937459238, -0.955400183967,  1.362016363174],
                         [-1.109932511965, -0.182939754747,  2.942043484298],
                         [-0.515413707857, -1.119341268799,  3.136533689731],
                         [-0.509862540826,  0.71770586625 ,  3.253250779134],
                         [-1.823114817881, -0.248387001392,  4.00605213455 ],
                         [-2.451181382366,  0.658629838415,  3.794745029733],
                         [-2.456019886489, -1.118078262521,  3.682204447835],
                         [-2.092097378568, -0.326797885494,  5.255445507069],
                         [-1.454808166348, -1.218140992161,  5.492314817703],
                         [-1.448149189819,  0.522735169126,  5.602345190585],
                         [-2.95020692258 , -0.368818356258,  5.97713874924 ]]*Angstrom

# Set up configuration
molecule_configuration = MoleculeConfiguration(
    elements=elements,
    cartesian_coordinates=cartesian_coordinates
    )

potentialSet = Tersoff_CH_2010()
calculator = TremoloXCalculator(parameters=potentialSet)

molecule_configuration.setCalculator(calculator)
molecule_configuration.update()

initial_velocity = MaxwellBoltzmannDistribution(
    temperature=300.0*Kelvin,
    remove_center_of_mass_momentum=True
)

method = Langevin(
    time_step=1*femtoSecond,
    reservoir_temperature=300*Kelvin,
    friction=0.01*femtoSecond**-1,
    initial_velocity=initial_velocity,
    heating_rate=0*Kelvin/picoSecond,
)

fix_atom_indices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
fix_atom_constraints = FixAtomConstraints(fix_atom_indices)

md_trajectory = MolecularDynamics(
    molecule_configuration,
    constraints=[fix_atom_constraints],
    trajectory_filename='decane_constraints.hdf5',
    steps=500,
    log_interval=10,
    method=method
)

molecule_configuration = md_trajectory.lastImage()

In the following example only the z-coordinates of the end atoms are fixed.


fix_atom_indices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
fix_atom_constraints = FixAtomConstraints(
    fix_atom_indices,
    fix_cartesian_direction=[False, False, True]
)

md_trajectory = MolecularDynamics(
    molecule_configuration,
    constraints=[fix_atom_constraints],
    trajectory_filename='decane_z_constraints.hdf5',
    steps=500,
    log_interval=10,
    method=method
)

Notes

  • FixAtomConstraints can be used in OptimizeGeometry and MolecularDynamics simulations to constrain the coordinates of the selected atoms to their initial positions by setting the velocities and forces on these atoms to zero.

  • It is not recommended to run cell-optimizations (i.e. optimization simulations with optimize_cell=True) or NPT simulations (e.g. NPTBerendsen) when fixed atoms are used.

  • With the fix_cartesian_direction parameter you fix individual cartesian components of the selected atoms.

  • You can specify more than one FixAtomConstraints object in the constraints list, e.g. one object which fixes only certain cartesian components of some atoms, and another one, which completely fixes another group of atoms.