Importing and exporting#
SAMSON provides an extensive set of importers and exporters by default: list of formats supported by default in SAMSON.
Note
More formats are supported through various extensions, see SAMSON Connect - Marketplace.
To import a file into SAMSON, use SAMSON.importFromFile().
To export a system from SAMSON into a file, use SAMSON.exportToFile().
Based on the file extension, SAMSON will detect which importer or exporter to use.
Some importers and exporters have additional options. If no options are specified in SAMSON.importFromFile() or SAMSON.exportToFile(), SAMSON may show a dialog asking the user to choose them.
Let us for example import a molecule, apply some random perturbations to it, and export the result. In this example, we assume that the active document is empty (i.e., it contains no atoms) before importing a molecule.
import numpy as np
# import molecule from a file in any supported format, e.g. pdb, xyz, mol2, sam
SAMSON.importFromFile('/path/to/molecule.pdb')
# get all atoms in the active document
atomIndexer = SAMSON.getNodes('node.type atom')
# apply some random perturbations to atoms
for atom in atomIndexer:
atom.setX(atom.getX() + SBQuantity.pm(10.0 * np.random.randn(1)))
atom.setY(atom.getY() + SBQuantity.pm(10.0 * np.random.randn(1)))
atom.setZ(atom.getZ() + SBQuantity.pm(10.0 * np.random.randn(1)))
# export nodes into one of the supported formats, e.g. pdb, xyz, mol2, sam
SAMSON.exportToFile(atomIndexer, '/path/to/molecule-modified.pdb')
Importers and exporters may have additional options. If you want to import or export using the default options already specified by the user, leave the parameters argument empty when calling SAMSON.importFromFile() or SAMSON.exportToFile().
Note
You can supply importer and exporter parameters via a map SBValueMap, which you can fill as a dictionary with a string as keys and SBValue as values.
# import with default options
SAMSON.importFromFile('/path/to/molecule.pdb')
# get all structural models from the active document
nodeIndexer = SAMSON.getNodes('node.type sm')
# export with default options
SAMSON.exportToFile(nodeIndexer, '/path/to/molecule.pdb')
Note
In SAMSON.importFromFile(), you can also specify a folder into which you would like to import a file. By default, it is imported in the active document.