transition_sampling.engines.cp2k package

Submodules

transition_sampling.engines.cp2k.CP2K_engine module

Engine implementation of CP2K

class transition_sampling.engines.cp2k.CP2K_engine.CP2KEngine(inputs, working_dir=None, **kwargs)

Bases: transition_sampling.engines.abstract_engine.AbstractEngine

Engine implementation of CP2K.

Relevant docstrings for overridden methods can be found in the base class.

Parameters

inputs (dict) –

In addition to the inputs required by AbstractEngine, CP2KEngine also requires

  • cp2k_inputsstr

    The path to the CP2K inputs file to use for the simulations. This file will not be modified

cp2k_inputs

The inputs associated with this engine. Used to do low level manipulation of the inputs.

Type

CP2KInputsHandler

property atoms: Sequence[str]

Get the atoms held by the engine.

Get a sequence of the string representations of the atoms in use by this engine. String representations are the same as the periodic table.

Return type

Sequence[str]

Returns

An ordered sequence of atoms in the engine.

property box_size: tuple

Get the box size of the engine in A.

Return type

tuple[float]

Returns

Box size (x, y, z) the engine is set to in A

flip_velocity()

Flip the velocities currently held by multiplying by -1

Return type

None

get_engine_str()

Get the string representation of this engine.

This string is what defines the engine name in the inputs dictionary.

Return type

str

Returns

String of the engine’s representation

set_delta_t(value)

Set the time offset of this engine. Set the value of the time offset of frame to save in femtoseconds. If this isn’t a multiple of the engine’s time step, the closest frame will be taken.

Parameters

value (float) – Time offset in femtoseconds

Return type

None

set_positions(positions)

Set the positions of atoms in the engine.

Positions are ordered for n atoms, in shape (n, 3). Rows represent atoms and columns represent (x, y, z) dimensions.

Parameters

positions (np.ndarray with shape (n, 3)) – The positions for atoms to be set to.

Raises

ValueError – If the array does not match the required specifications

Return type

None

set_velocities(velocities)

Set the velocities of atoms in the engine.

Velocities are ordered for n atoms, in shape (n, 3). Rows represent atoms and columns represent (x, y, z) dimensions.

Parameters

velocities (np.ndarray with shape (n, 3)) – The velocities for atoms to be set to.

Raises

ValueError – If the array does not match the required specifications

Return type

None

validate_inputs(inputs)

Validate the given inputs for the specific engine.

Given a dictionary input, validate that it represents a well-formed input with all requirements for this engine

Parameters

inputs – dict of engine-specific inputs

Returns

  • (True, “”) if the inputs passed validation. Otherwise,

  • (False, “<Relevant Error Message>”)

transition_sampling.engines.cp2k.CP2K_inputs module

class transition_sampling.engines.cp2k.CP2K_inputs.CP2KInputsHandler(cp2k_inputs_file, logger=None)

Bases: object

Handles manipulating the raw CP2K Inputs data structure.

This class parses a CP2K inputs file into a memory, then supplies methods for altering it. The original file is not modified. Once the in-memory inputs have been changed, the current state can be written out into an equivalent CP2K inputs file.

Parameters

cp2k_inputs_file (str) – The cp2k inputs file that serves as a template for this class

cp2k_dict

The in-memory data structure representing the current inputs

Type

dict

property atoms: list

Get the atoms in this input

Gets the name of the atoms in the inputs as represented by CP2K.

Return type

list[str]

Returns

An ordered sequence of atoms in the inputs.

property box_size: list

Get the box_size of the input in A.

Return type

list[float]

Returns

Box size [x, y, z] of the input is set to in A

flip_velocity()

Modify state by multiplying every velocity component by -1

Return type

None

read_timestep()

Gets the time per frame in femtoseconds

Return type

float

Returns

How many femtoseconds each frame is given

set_plumed_file(plumed_file_path)

Set the plumed input file to the passed path

Parameters

plumed_file_path (str) – The full path of the plumed input file

Return type

None

set_positions(positions)

Set the positions of atoms in the inputs.

Positions are ordered for n atoms, in shape (n, 3). Rows represent atoms and columns represent (x, y, z) dimensions.

Parameters

positions (np.ndarray with shape (n, 3)) – The positions for atoms to be set to.

Return type

None

set_project_name(projname)

Set the CP2K project name of the inputs

Parameters

projname (str) – The project name to be set

Return type

None

set_traj_print_file(file_path)

Set the file the traj will be printed to. Appended with -pos-1.xyz

Note that cp2k automatically appends -pos-1.xyz to this filename.

Parameters

file_path (str) – The path the trajectory will be printed to

Return type

None

set_traj_print_freq(step)

Set how often the trajectory should be printed

Parameters

step (int) – The number of MD steps between each print. Must be an integer and must be greater than 0

Raises

ValueError – if step is not an integer or greater than 0

Return type

None

set_velocities(velocities)

Set the velocities of atoms in the inputs.

Velocities are ordered for n atoms, in shape (n, 3). Rows represent atoms and columns represent (x, y, z) dimensions.

Parameters

velocities (np.ndarray with shape (n, 3)) – The positions for atoms to be set to.

Return type

None

property temp: float

Get the temperature of the input.

Return type

float

Returns

Temperature the input is set to in Kelvin

write_cp2k_inputs(filename)

Write the current state of the inputs to the passed file name.

Creates the standard cp2k input format. Overwrites anything present.

Parameters

filename (str) – The file to write the input to

Return type

None

transition_sampling.engines.cp2k.CP2K_outputs module

class transition_sampling.engines.cp2k.CP2K_outputs.CP2KOutputHandler(name, working_dir)

Bases: object

check_warnings()

Check the output file for any warnings.

Returns a list of warnings. The list is empty if there are none.

Return type

Sequence

Returns

A list of warnings from this output file

copy_out_file(new_location)

Copy the output file to a new location

Parameters

new_location (str) – The full path of the location to copy to

Return type

None

get_out_file()

Get the full name of the output file

Return type

str

Returns

Full path of output file

read_frames_2_3()

Read the second (first t!=0) and third frames from the trajectory

Return type

ndarray

Returns

  • Array of the xyz coordinates in the second and third frame. Has the

  • shape (2, n_atoms, 3).

Raises

EOFError – If EOF was reached before the end of the third frame

Module contents