Importing and exporting#

SAMSON provides an extensive set of various 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 load/import a file in SAMSON, you can use the SAMSON.importFromFile() function. To export a system from SAMSON in a file, you can use the SAMSON.exportToFile() function. Based on the file extension, SAMSON will detect which importer or exporter to use.

Some importers and exporters might have additional options. In this case, if no options were specified in the SAMSON.importFromFile() or SAMSON.exportToFile() functions then a pop-up dialog will appear asking the user to choose the options.

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. pdf, xyz, mol2, sam
SAMSON.importFromFile('/path/to/molecule.pdb')

# apply some random perturbations to atoms of the active document
atomIndexer = SAMSON.getNodes('node.type atom')
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 might have additional options. In this case, if no options are provided then a pop-up dialog will appear. If you want to import or export using the default options already specified by the user then supply [] as a parameters to SAMSON.importFromFile() or SAMSON.exportToFile() functions.

# import with default options ([])
SAMSON.importFromFile('/path/to/molecule.pdb', [])

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.