Molecule

Methods to interact with molecule, including loading data, querying molecule attributes, working with volumetric data, or setting its visibility in the render window.

Basic functionality

cancel Cancel background loading of files for given molid
delete Delete a molecule
delframe Delete a frame or frame(s) from a loaded molecule
dupframe Duplicate a frame.
exists Check if a molecule ID is valid
listall List all valid molecule IDs
load Load a molecule from a file.
new Create a new molecule, with optional number of ‘empty’ atoms
num Get the number of loaded molecules
read Read coordinate data into an existing molecule
rename Change the name of a molecule
write Write coordinate and topology data from a loaded molecule to a file
ssrecalc Recalculate secondary structure for molecule

Typically for molecular dynamics simulation trajectories, a topology file will be loaded, then a trajectory file will be read in to it in a way that blocks program execution until all frames are done loading. This code snippit does this, then saves the last frame as a PDB file.

from vmd import molecule

molid = molecule.load("parm7", "system.prmtop")
molecule.read(molid, "netcdf", "simulation.nc", skip=5, waitfor=-1)
last_frame = molecule.numframes - 1
molecule.write(molid, "pdb", "last_frame.pdb", first=last_frame)

VMD has the concept of the “top” molecule, which is the default molecule for all operations unless otherwise specified.

get_top Get the ID of the top molecule
set_top Set the top molecule

Querying loaded molecules

Depending on the information available in the input molecule files, these fields may or may not be populated.

get_accessions Get database accession codes associated with files loaded into a molecule
get_databases Get databases associated with files loaded into a molecule
get_periodic Get the periodic cell layout
get_physical_time Get the physical time value for a frame, if set
get_remarks Get remarks associated with files loaded into a molecule
set_periodic Set the periodic cell layout for a particular frame.
set_physical_time Set the physical time value for a frame

These attributes are always available:

get_filenames Get list of all files loaded into a molecule
get_filetypes Get file types loaded into a molecule
get_frame Get the current frame
get_visible Get if a molecule is visible
name Get name of a given molecule
numatoms Get number of atoms in a given molecule
numframes Get the number of loaded frames in a molecule
set_frame Set the frame of a molecule
set_visible Set the visiblity of a molecule

Working with volumetric data

add_volumetric Add a new volumetric dataset to a molecule
delete_volumetric Delete a volumetric dataset from a molecule
get_volumetric Obtain a volumetric dataset loaded into a molecule
num_volumetric Get the number of volumetric datasets loaded into a molecule