Export trajectory frames#
This example demonstrates how to export structures for each frame along a trajectory (SBPath
).
def export_trajectory(path, file_basename, file_format):
'''
Exports trajectories from an SBPath node 'path'
to files with a name starting with 'file_basename' and extension 'file_format'
'''
# set the current step for the Path to 0
path.currentStep = 0
trajectory_files = []
# get a node indexer for all structural models
indexer = SAMSON.getNodes('n.t sm')
if len(indexer):
# loop over steps in the Path
for step in range(path.numberOfSteps):
# increment the current step
path.currentStep = step
# a name of a file
fn = file_basename + str(step) + '.' + file_format
# export current trajectory into a file 'fn' with default parameters ([])
if SAMSON.exportToFile(indexer, fn, []):
# append list of trajectory files
trajectory_files.append(fn)
# return list of trajectory files
return trajectory_files
def export_to_PDB(path, file_basename):
'''
Export trajectory from path into PDB format
'''
return export_trajectory(path, file_basename, 'pdb')
def export_to_XYZ(path, filename):
'''
Export trajectory from path into XYZ format
'''
return export_trajectory(path, file_basename, 'xyz')
# get an indexer with all paths in the active document
path_indexer = SAMSON.getNodes('node.type path')
if len(path_indexer):
# take the first path
path = path_indexer[0]
# export the path to a pdb file
export_to_PDB(path, "/path/to/filename")