narupa.ase.converter module¶
Module containing methods for converting between ASE simulations consisting of
Atoms
and the Narupa FrameData
object for transmission to
Narupa clients.
-
narupa.ase.converter.
add_ase_box_vectors_to_frame_data
(data: narupa.trajectory.frame_data.FrameData, ase_atoms: ase.atoms.Atoms)¶ Adds the periodic box vectors from the given ASE
Atoms
object to the givenFrameData
.Parameters: - data –
FrameData
upon which to add periodic box vectors. - ase_atoms –
Atoms
from which to extract periodic box vectors.
- data –
-
narupa.ase.converter.
add_ase_positions_to_frame_data
(data: narupa.trajectory.frame_data.FrameData, positions: numpy.array)¶ Adds ASE positions to the frame data, converting to nanometers.
Parameters: - data –
FrameData
to add atom positions to. - positions – Array of atomic positions, in angstroms.
- data –
-
narupa.ase.converter.
add_ase_state_to_frame_data
(frame_data: narupa.trajectory.frame_data.FrameData, ase_atoms: ase.atoms.Atoms)¶ Adds simulation state information to the frame, consisting of the potential energy and kinetic energy.
Parameters: - frame_data – Frame data to add ASE state information to.
- ase_atoms – The ASE atoms from which to extract state information.
-
narupa.ase.converter.
add_ase_topology_to_frame_data
(frame_data: narupa.trajectory.frame_data.FrameData, ase_atoms: ase.atoms.Atoms, generate_bonds=True)¶ Generates a topology for the current state of the atoms and adds it to the frame.
Since ASE atoms have no concept of bonds, they are generated using distance criteria.
Parameters: - frame_data – Frame data to add topology information to.
- ase_atoms – ASE atoms to extract topology information from.
-
narupa.ase.converter.
add_frame_data_positions_to_ase
(frame_data, ase_atoms)¶ Adds frame data particle positions to ASE atoms, converting to angstroms.
Parameters: - frame_data –
FrameData
from which to extract positions. - ase_atoms – ASE
Atoms
to add particle positions to.
- frame_data –
-
narupa.ase.converter.
add_frame_data_topology_to_ase
(frame_data: narupa.trajectory.frame_data.FrameData, atoms: ase.atoms.Atoms)¶ Adds frame data topology information to ASE
Atoms
.Since ASE
Atoms
do not have a concept of bonds, this just adds particle elements.Parameters: - frame_data –
FrameData
from which to extract topology. - atoms – ASE
Atoms
to add element data to.
- frame_data –
-
narupa.ase.converter.
ase_to_frame_data
(ase_atoms: ase.atoms.Atoms, positions: bool = True, topology: bool = True, state: bool = True, box_vectors: bool = True, generate_bonds: bool = True) → narupa.trajectory.frame_data.FrameData¶ Constructs a Narupa frame from the state of the atoms in an ASE simulation.
Parameters: - ase_atoms – The ASE atoms object representing the state of the simulation to send.
- positions – Whether to add positions to the frame.
- topology – Whether to generate the current state of the topology and add it to the frame.
- state – Whether to add additional state information such as energies.
- box_vectors – Whether to add the box vectors to the frame data.
- generate_bonds – Whether to generate bonds for the topology.
Returns: Narupa frame.
Raises: AttributeError Raised if state is True, and ase_atoms has no calculator attached.
>>> atoms = Atoms('CO', positions=[(0, 0, 0), (0, 0, 1.1)], cell=[2, 2, 2]) >>> frame = ase_to_frame_data(atoms, state=False) >>> frame.particle_count 2 >>> frame.bonds [[0, 1]] >>> frame.particle_elements [6, 8]
-
narupa.ase.converter.
frame_data_to_ase
(frame_data: narupa.trajectory.frame_data.FrameData, positions: bool = True, topology: bool = True, ase_atoms: Optional[ase.atoms.Atoms] = None) → ase.atoms.Atoms¶ Constructs an ASE
Atoms
object from a NarupaFrameData
.Parameters: - frame_data – The Narupa
FrameData
. - positions – Whether to add positions to the ASE atoms.
- topology – Whether to add topology information within the frame data to ASE.
- ase_atoms – Optional ASE
Atoms
object, which will have its positions replaced. If the flag topology is set, then a new object will still be constructed.
Returns: ASE Atoms updated or created with the data contained in the Narupa frame.
>>> frame = FrameData() >>> frame.particle_elements = [6, 8] >>> frame.particle_positions = [[0,0,0], [0,0, 0.11]] >>> atoms = frame_data_to_ase(frame) >>> atoms.symbols Symbols('CO')
- frame_data – The Narupa
-
narupa.ase.converter.
generate_bonds_from_ase
(atoms: ase.atoms.Atoms)¶ Generates bonds for the given configuration of ASE atoms using a distance criterion.
A bond is placed between two atoms if the distance between them is less than 0.6 times the VDW radii of the atoms.
Parameters: atoms – ASE atoms to generate bonds for. Returns: A list of pairs of atom indexes representing bonds. The following example produces a bond between the two atoms in a carbon monoxide molecule:
>>> co = Atoms('CO', positions=[(0, 0, 0), (0, 0, 1.1)], cell=[2, 2, 2]) >>> generate_bonds(co) [[0, 1]]
-
narupa.ase.converter.
get_radius_of_element
(symbol: str, default=1.0)¶ Gets the radius of an atom in Angstroms.
Parameters: - symbol – The chemical symbol representing the element.
- default – Default radius to use if the radius for the given chemical symbol is not known.
Returns: The VDW radius of the atom in angstroms.