User Interface
Atom
The Atom class is a useful way of keeping track of properties of an atom, such as its atomic number, charge and position
- class render_molecules.atom.Atom(atomic_number: int, element: str, charge: float, x: float, y: float, z: float, is_angstrom: bool)[source]
Bases:
object- Parameters:
atomicNumber (int) – atomic number. For example, for iron atom, 26
element (str) – element. For example, for iron atom, Fe
charge (float) – charge of atom
x (float) – x-coordinate
y (float) – y-coordinate
z (float) – z-coordinate
isAngstrom (bool) – whether coordinates are in Angstrom. If False, assume in Bohr
- classmethod from_cube_string(string: str)[source]
Create Atom instance from a line in a CUBE file
- Parameters:
string (str) – line in CUBE file
- classmethod from_xyz_string(string: str)[source]
Create Atom instance from a line in an XYZ file
- Parameters:
string (str) – line from an XYZ file. Formatted as A x y z …, where A is either atomic number or element string
- classmethod from_sdf_string(string: str)[source]
Create Atom instance from a line in an SDF file
- Parameters:
string (str) – line from an SDF file. Formatted as x y z A, where A is an element string.
- get_atomic_number() int[source]
Get the atomic number of the atom
- Returns:
atomic number
- Return type:
int
- get_charge() float[source]
Get the charge of the Atom (undefined if created from XYZ file)
- Returns:
charge of Atom
- Return type:
float
- get_x() float[source]
Get the x-coordinate of the atom
- Returns:
x-coordinate of Atom
- Return type:
float
- get_y() float[source]
Get the y-coordinate of the atom
- Returns:
y-coordinate of Atom
- Return type:
float
- get_z() float[source]
Get the z-coordinate of the atom
- Returns:
z-coordinate of Atom
- Return type:
float
- get_position() ndarray[float][source]
Get position of the atom
- Returns:
array with x, y and z coordinates of Atom
- Return type:
ndarray
- set_position(new_position) None[source]
Set the position of the atom to a new position
- Parameters:
newPosition (ndarray) – x, y and z coordinates of new position
Bond
- class render_molecules.bond.Bond(atom1_index: int, atom2_index: int, bond_type: str, bond_length: float, interatomic_vector: ndarray, midpoint_position: ndarray, atom1_and_2_pos: ndarray, name: str)[source]
Bases:
object- get_axis_angle_with_z() tuple[float, float, float, float][source]
Get the axis angle such that a created cylinder in the direction of the bond
Structure
- class render_molecules.structure.Structure(atoms: list[Atom], bonds: list[Bond] | None = None)[source]
Bases:
GeometryAn easy way to keep track of the geometry of a molecule or system.
- Parameters:
- create_atoms(resolution: RenderResolution = RenderResolution.MEDIUM, create_mesh: bool = True, force_material_creation: bool = False, atom_colors: dict[str, str] | None = None) None[source]
Create the atoms in the scene
- Parameters:
resolution (RenderResolution) – resolution of created spheres.
create_mesh (bool) – create mesh of vertices. saves memory, but atom positions cannot be animated
force_material_creation (bool) – force creation of new materials with element names, even though materials with that name already exist. This is useful for if you want to change the atom colors
atom_colors (dict) – dictionary of atom colors, with keys elements and values hex-codes. If None, use the
element_data.manifest['atom_colors']. Can also be partially filled, e.g. only contain{'H': 'FFFFFF'}for H2O, and then the color of O atoms will be filled by the values inelement_data.manifest['atom_colors'].
- find_bonds_from_distances() list[Bond][source]
Create bonds based on the geometry
- Returns:
list of bonds in the structure. Cached
- Return type:
list[Bond]
- generate_bond_order_bond(bond: Bond, bond_order: int, camera_position: ndarray[float], displacement_scaler=0.2) list[Bond][source]
Way to generate multiple bonds, for example in CO2 molecule double bonds, or CO triple bonds.
- Parameters:
bond (Bond) – bond to change to the desired bond order.
bond_order (int) – desired bond order.
camera_position (np.ndarray[float]) – position of camera.
displacement_scaler (float) – how much to displace the bonds from eachother. Default = 0.2 Angstrom
- Returns:
bond instances of newly generated bonds
- Return type:
list[Bond]
- get_bonds() list[Bond][source]
Get all bonds in the system
- Returns:
list of bond instances in the Structure
- Return type:
list[Bond]
- get_center_of_mass() ndarray[float][source]
Get the center of mass position vector
- Returns:
center of mass position vector in Angstrom
- Return type:
com (np.ndarray)
- set_center_of_mass(new_center_of_mass: ndarray | list) None[source]
Set the Center Of Mass (COM) of the whole system to a new position
- Parameters:
new_center_of_mass (ndarray) – new COM position
- set_average_position(new_average_position: ndarray | list) None[source]
Sets the average position of all atoms to a new position
- translate(translation_vector: ndarray) None[source]
Translate every atom in the Structure along a vector
- Parameters:
translationVector (ndarray) – vector to translate every atom
- get_total_charge() int[source]
Get the total charge in the system
- Returns:
total charge of the system
- Return type:
total_charge (int)
- get_nr_electrons() int[source]
Get the total amount of electrons in the system
- Returns:
total number of electrons in the system
- Return type:
total_electrons (int)
- is_radical() bool[source]
Returns whether the studied structure is a radical (has an uneven amount of electrons)
- Returns:
whether the system is a radical or not
- Return type:
bool
- rotate_around_axis(axis: ndarray, angle: float) None[source]
Rotate the structure around a certain axis
- Parameters:
axis (ndarray) – 3D vector around which to rotate the structure
angle (float) – angle with which to rotate the structure. Given in angles, counterclockwise
- get_inertia_tensor() ndarray[source]
Get the moment of inertia tensor
- Returns:
inertia tensor in kg m^2
- Return type:
inertiaTensor (ndarray)
- get_principal_moments_of_inertia() tuple[ndarray, ndarray][source]
Get the principal moments of inertia and the principal axes
- Returns:
array of length 3 with the three principal moments of inertia in kg m^2 principalAxes (ndarray): matrix of shape 3x3 with three principal moment axes
- Return type:
principalMoments (ndarray)
- create_bonds(bonds: list[Bond] | None = None, split_bond_to_atom_materials: bool = True, resolution: RenderResolution = RenderResolution.MEDIUM, atom_colors: dict | None = None, force_material_creation: bool = False) None[source]
Create the bonds in the Blender scene
- Parameters:
bonds (list[Bond] | None) – list of bonds to be drawn, or None. If None, will be determined from self.find_bonds_from_distances(). Default: None
split_bond_to_atom_materials (bool) – whether to split up the bonds to the two atom materials connecting them
resolution (RenderResolution) – render resolution.
atom_colors (dict) – dictionary of atom colors, with keys elements and values hex-codes. If None, use the
element_data.manifest['atom_colors']. Can also be partially filled, e.g. only contain{'H': 'FFFFFF'}for H2O, and then the color of O atoms will be filled by the values inelement_data.manifest['atom_colors'].force_material_creation (bool) – force creation of new materials with element names, even though materials with that name already exist. This is useful for if you want to change the atom colors
- create_structure(resolution: RenderResolution = RenderResolution.MEDIUM, create_mesh: bool = True, atom_colors: dict | None = None, split_bond_to_atom_materials: bool = True, force_material_creation: bool = False) None[source]
Create the atoms and bond in the scene
- Parameters:
resolution (RenderResolution) – resolution of created spheres.
create_mesh (bool) – create mesh of vertices. saves memory, but atom positions cannot be animated
force_material_creation (bool) – force creation of new materials with element names, even though materials with that name already exist. This is useful for if you want to change the atom colors
atom_colors (dict) – dictionary of atom colors, with keys elements and values hex-codes. If None, use the
element_data.manifest['atom_colors']. Can also be partially filled, e.g. only contain{'H': 'FFFFFF'}for H2O, and then the color of O atoms will be filled by the values inelement_data.manifest['atom_colors'].split_bond_to_atom_materials (bool) – whether to split up the bonds to the two atom materials connecting them
force_material_creation – force creation of new materials with element names, even though materials with that name already exist. This is useful for if you want to change the atom colors
- displace_atoms(displacements: ndarray) None[source]
Displace all atoms along different displacement vectors
- Parameters:
displacements (ndarray) – matrix of shape natoms * 3, vectors to displace atoms
- classmethod from_xyz(filepath: str | Path, index: int = -1) Structure[source]
Create a Structure from an XYZ file
- Parameters:
filepath (str | Path) – XYZ file to read
index (int) – index to read. Default: -1, last. TODO: Implement
- classmethod from_orca(filepath: str | Path, index: int = -1) Structure[source]
Create a structure from an ORCA output file. Reads the cartesian coordinates in the input.
- Parameters:
filepath (str | Path) – orca output file to read
- class render_molecules.structure.CUBEfile(filepath: str)[source]
Bases:
StructureAn easy way to keep track of the geometry of a molecule or system.
- Parameters:
- get_volumetric_origin_vector() ndarray[float][source]
Get the origin vector of the volumetric data
- Returns:
np.ndarray of length 3 corresponding to x, y and z coordinates of volumetric origin
- Return type:
ndarray
- get_volumetric_axis_vectors() ndarray[float][source]
Get the axis vectors of the volumetric data
- Returns:
np.ndarray of length 3 corresponding to i, j and k axis vectors of volumetric data
- Return type:
ndarray
- get_volumetric_data() ndarray[float][source]
Get the volumetric data
- Returns:
matrix of shape NX*NY*NZ containing volumetric data
- Return type:
ndarray
- write_ply(filepath: str, isovalue: float) None[source]
Write the volumetric data to a filepath
- Parameters:
filepath (str) – filepath to write to
isovalue (float) – isovalue to use to calculate the isosurface
- calculate_isosurface(isovalue: float, step_size: int = 1) tuple[ndarray, ndarray, ndarray, ndarray][source]
Calculate the isosurface from the volumetric data and an isovalue
- Parameters:
isovalue (float) – value where to calculate the isosurface
step_size (int) – step size in the grid. Larger values result in coarser, but quicker, results. Default = 1
- Returns:
Vx3 array of floats corresponding to vertex positions faces (np.ndarray): Fx3 array of integers corresponding to vertex indices normals (np.ndarray): Vx3 array of floats corresponding to normal direction at each vertex values (np.ndarray): Vx1 array of maximum value in data close to each vertex
- Return type:
vertices (np.ndarray)
Trajectory
- class render_molecules.trajectory.Trajectory(frames: list[Structure])[source]
Bases:
Geometry- set_center_of_mass(new_center_of_mass: ndarray, frame_index: int = 0) None[source]
Set the Center Of Mass (COM) of the structure at index ‘frameIndex’ to a new position
- Parameters:
newCOMposition (np.ndarray) – new COM position [x, y, z], in Angstrom
frameIndex (int) – frame index to position according to COM
- create_animation(create_bonds: bool = True, resolution: RenderResolution = RenderResolution.MEDIUM, split_bond_to_atom_materials: bool = True) None[source]
Create the animation of the trajectory in the Blender scene
- Parameters:
create_bonds (bool) – Whether to create the bonds in the scene. Default: True
resolution (RenderResolution) – resolution of created Blender objects
split_bond_to_atom_materials (bool) – Whether to use the same material on the bonds as the atoms. Default: True
- get_frame(frame_index: int) Structure[source]
Get the Structure at a certain frame index
- Parameters:
frame_index (int) – index of frame
- Returns:
structure at that frame index
- Return type:
- rotate_around_axis(axis: ndarray, angle: float) None[source]
Rotate all frames in the trajectory around an axis counterclockwise with a certain angle in degrees
- Parameters:
axis (np.ndarray) – axis of rotation
angle (float) – rotation angle in degrees
- classmethod from_xyz(filepath: str) Structure[source]
Generate a trajectory from an XYZ file containing multiple frames
- Parameters:
filepath (str) – filepath of ORCA geometry optimization
- classmethod from_orca(filepath: str, use_vibrations: bool = True, use_geometry_optimization: bool = False, vibration_nr: str | int = 'imag', n_frames_per_oscillation: int = 20, amplitude: float = 0.5) Structure[source]
Get a Trajectory from an ORCA output file.
- Parameters:
filepath (str) – filepath of ORCA output file
use_vibrations (bool) – whether to use the vibrations
use_geometry_optimization (bool)
vibration_nr (str | int) – vibration number index, or string (then has to be one of
['i', 'im', 'imag', 'imaginary']). Vibration number index is 0-indexed (i.e. 0 is the first vibrational mode, 1 is the second, etc.)n_frames_per_oscillation (int) – number of keyframes per full vibrational oscillation (phase= \(2\pi\))
amplitude (float) – amplitude of vibrations. 0.5 seems to be a good default value.
Notes
Tries to find imaginary mode from the output. If multiple imaginary modes are found, will raise an error. Please investigate the output file manually to see which one you want to visualize, and give the integer index to this function instead.
Calculates the vibrational trajectory from the normal modes. ORCA outputs the translational and rotational modes as vibrations too, meaning that often the first 6 vibrations (so up to and including
vibration_nr=5) have no displacements, and the resulting Trajectory will show no movement.
Geometry
- class render_molecules.geometry.Geometry[source]
Bases:
object- rotate_around_x(angle: float) None[source]
Rotate the geometry around the x-axis counterclockwise with a certain angle in degrees
- render_molecules.geometry.rotation_matrix(axis: list | ndarray, theta: float) ndarray[source]
Return the rotation matrix associated with counterclockwise rotation about the given axis by theta degrees.
- render_molecules.geometry.angle_between(vector1: ndarray | list, vector2: ndarray | list) float[source]
Get the angle between two vectors.
- Parameters:
vector1 (ndarray) – list or np array of length 3
vector2 (ndarray) – list or np array of length 3
- Returns:
angle between two vectors in degrees
- Return type:
float
Blender utilities
- class render_molecules.blender_utils.RenderResolution(value)[source]
Bases:
EnumConvenient way to keep track of scaling
- VERY_LOW = 0.25
- LOW = 0.5
- MEDIUM = 1
- HIGH = 2
- VERY_HIGH = 4
- render_molecules.blender_utils.create_uv_sphere(element: str, position: ndarray, resolution: RenderResolution = RenderResolution.MEDIUM) object[source]
- render_molecules.blender_utils.create_mesh_of_atoms(positions: ndarray, reference_sphere: object, element: str) None[source]
- render_molecules.blender_utils.material_exists(material_name: str) bpy.types.Material[source]
Function to determine whether a material already exists. WIP
- render_molecules.blender_utils.create_material(name: str, color: str, alpha: float = 1.0, force: bool = False) object[source]
Build a new material
- Parameters:
name (str) – name of material
color (str) – color of material
alpha (float) – transparency of material
force (bool) – whether to force creation of the new material, regardless of if another material with that name already exists. If True, will remove other materials with that same name.
- Returns:
created material
- Return type:
mat (object)
Notes
If a material with name
namealready exists andforce=Falseis used, returns that material instead.
- render_molecules.blender_utils.delete_all_objects()[source]
Deletes all objects in the current scene
- render_molecules.blender_utils.create_isosurface(verts: ndarray, faces: ndarray, prefix: str = 'isosurface', isovalue: float | None = None, color: str = 'sign', alpha: float = 0.5) None[source]
Creates isosurface from vertices and faces output from a marching cubes calculation.
- Parameters:
verts (np.ndarray) – Vx3 array of floats corresponding to vertex positions
faces (np.ndarray) – Fx3 array of integers corresponding to vertex indices
isovalue (float | None) – isovalue used to calculate the isosurface. Only necessary if color=”sign”.
prefix (str) – prefix to put in front of the isovalue to get its name
color (str) – color of isosurface. Can also be “sign”, and then it is colored using the sign of isovalue, and the constants.manifest[‘isosurface_color_negative’] or constants.manifest[‘isosurface_color_positive’].
alpha (float) – transparency of created isosurface.
Notes
render_molecules.structure.CUBEfile.calculate_isosurface()can be used to calculate the vertices and faces.This function creates a material called
Isosurface. Once created, any timecreate_isosurfaceis called again, it will callcreate_materialagain with the same name. That will return the original material again, so the new isosurface will have the same color and transparency. This is something I will have to fix somehow. Maybe by adding amaterial_nameargument to this function, which can be changed by the user so that if they wish to have a different material on a second isosurface they simply specify a different material name for the two isosurfaces?
- render_molecules.blender_utils.assign_isosurface_material_based_on_sign(isosurface_obj: object, isovalue: float, alpha=0.5) None[source]
- render_molecules.blender_utils.adjust_settings(is_one_render: bool = True, transparent_background: bool = True) None[source]
- render_molecules.blender_utils.outline_in_render(render_outline: bool = True, thickness: float = 5) None[source]
- render_molecules.blender_utils.select_object_by_name(name: str, select=True) None[source]
Select an object in the Blender scene from its name
- Parameters:
name (str) – name of object to select
select (bool) – whether to select it or not (aka deselect)
- render_molecules.blender_utils.get_object_by_name(name: str) object[source]
Get an object in the Blender scene from its name
- Parameters:
name (str) – name of object to obtain
- Returns:
object in Blender scene with the name
name- Return type:
object
- render_molecules.blender_utils.create_cylinder(location: ndarray, angle: float, thickness: float, length: float, resolution: RenderResolution = RenderResolution.MEDIUM, name: str = 'Cylinder') object[source]
Create a cylinder in the Blender scene.
- Parameters:
location (np.ndarray) – midpoint position of cylinder
angle (float) – angle with z-axis in radians
thickness (float) – radius of created cylinder
length (float) – length of created cylinder
resolution (RenderResolution) – desired object resolution.
name (str) – name of created cylinder
- Returns:
Blender object
- Return type:
obj (object)
- render_molecules.blender_utils.join_two_cylinders(cylinder1, cylinder2, center_position, select_within)[source]
- render_molecules.blender_utils.join_cylinders(cylinders: list[object], atom_position: ndarray, vdw_radius: float)[source]
- render_molecules.blender_utils.scale_vertices(*args, resolution: RenderResolution = RenderResolution.MEDIUM) int | tuple[int][source]
Scale number of vertices according to resolution
- Parameters:
*args – number of vertices. Can also be multiple arguments.
resolution (RenderResolution) – desired object resolution.
- Returns:
scaled number of vertices. The same number of return values as the number of
*args.- Return type:
int | tuple
Other utilities
- render_molecules.other_utils.hex2rgbtuple(hexcode: str) tuple[float, float, float][source]
Convert 6-digit color hexcode to a tuple of floats
- render_molecules.other_utils.color_srgb_to_scene_linear(c: float) float[source]
Convert RGB to sRGB
- render_molecules.other_utils.find_first_string_in_list_of_strings(string_to_find: str | list[str], list_of_strings: list[str], start: int = 0, end: int | None = None) int | None[source]
Finds the first instance of a string in a list of strings.
Elemental data
Constants
- render_molecules.constants.BOHR_TO_ANGSTROM = 0.5291177249
Angstrom per Bohr
- render_molecules.constants.ANGSTROM_TO_BOHR = 1.8899385768809651
Bohr per Angstrom
- render_molecules.constants.BOHR_TO_METERS = 5.2917721067121e-11
Meter per Bohr
- render_molecules.constants.METERS_TO_BOHR = 18897261254.535072
Bohr per Meter
- render_molecules.constants.ANGSTROM_TO_METERS = 1e-10
Meter per Angstrom
- render_molecules.constants.METERS_TO_ANGSTROM = 10000000000.0
Angstrom per Meter
- render_molecules.constants.AMU_TO_KG = 1.66053907e-27
kg per amu
- render_molecules.constants.KG_TO_AMU = 6.0221407497506215e+26
amu per kg
- render_molecules.constants.KGM2_TO_AMU_ANGSTROM2 = 6.022140749750622e+46
amu angstrom2 per kg m2
- render_molecules.constants.HYDROGEN_BOND_LENGTH = 3.5
Maximum hydrogen bond length
- render_molecules.constants.HYDROGEN_BOND_ANGLE = 35.0
Maximum hydrogen bond angle
- render_molecules.constants.SPHERE_SCALE = 0.3
Fraction of Van der Waals radius for created spheres
- render_molecules.constants.CYLINDER_LENGTH_FRACTION_SPLIT = 0.25
Cylinder length fraction for a bond split between two materials
- render_molecules.constants.CYLINDER_LENGTH_FRACTION = 0.5
Cylinder length fraction for a bond