nanover.ase.converter module

Module containing methods for converting between ASE simulations consisting of Atoms and the NanoVer FrameData object for transmission to NanoVer clients.

nanover.ase.converter.add_ase_box_vectors_to_frame_data(data: FrameData, ase_atoms: Atoms)

Adds the periodic box vectors from the given ASE Atoms object to the given FrameData.

Parameters:
  • dataFrameData upon which to add periodic box vectors.

  • ase_atomsAtoms from which to extract periodic box vectors.

nanover.ase.converter.add_ase_positions_to_frame_data(data: FrameData, positions: ndarray[Any, dtype[_ScalarType_co]])

Adds ASE positions to the frame data, converting to nanometers.

Parameters:
  • dataFrameData to add atom positions to.

  • positions – Array of atomic positions, in angstroms.

nanover.ase.converter.add_ase_state_to_frame_data(frame_data: FrameData, 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.

nanover.ase.converter.add_ase_topology_to_frame_data(frame_data: FrameData, 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.

nanover.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_dataFrameData from which to extract positions.

  • ase_atoms – ASE Atoms to add particle positions to.

nanover.ase.converter.add_frame_data_topology_to_ase(frame_data: FrameData, 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_dataFrameData from which to extract topology.

  • atoms – ASE Atoms to add element data to.

nanover.ase.converter.ase_atoms_to_frame_data(ase_atoms: Atoms, *, topology: bool, **kwargs) FrameData
nanover.ase.converter.ase_to_frame_data(ase_atoms: Atoms, positions=True, topology=True, state=True, box_vectors=True, generate_bonds=True, include_velocities=False, include_forces=False) FrameData

Constructs a NanoVer 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.

  • include_velocities – Whether to includes per particle velocities.

  • include_forces – Whether to include per particle forces.

Returns:

NanoVer frame.

Raises:

AttributeError Raised if state is True, and ase_atoms has no calculator attached.

Example

>>> 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]
nanover.ase.converter.frame_data_to_ase(frame_data: FrameData, positions: bool = True, topology: bool = True, ase_atoms: Atoms | None = None) Atoms

Constructs an ASE Atoms object from a NanoVer FrameData.

Parameters:
  • frame_data – The NanoVer 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 NanoVer frame.

Example:

>>> 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')
nanover.ase.converter.generate_bonds_from_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.

Example

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]]
nanover.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.