Name

nlsave — Function for saving the given object to a NetCDF file.

Synopsis

Namespace: NanoLanguage
nlsave(
filename,
nl_object,
object_id,
labels,
comment
)

Description

Function for saving the given object to a NetCDF file. Returns: None.

nlsave Arguments

filename

The full or relative filename path that the NanoLanguage object should be saved to.

Type: A string.

nl_object

The NanoLanguage object that should be saved to a NetCDF file.

Type: A NanoLanguage object that supports saving to a NetCDF file.

object_id

A unique identifier that should be attached to the saved object.

Type: A string.

Default: The empty string ''.
labels

A list of strings that can serve to tag the object with.

Type: A sequence of strings.

Default: A list containing the empty string [''].
comment

A free-text descriptive comment string that should be attached to the saved object.

Type: A string.

Default: The empty string ''.

Usage Examples

Save the self-consistent state of a calculation:

# Set up configuration
molecule_configuration = MoleculeConfiguration(
    elements=[Nitrogen, Hydrogen, Hydrogen, Hydrogen],
    cartesian_coordinates=[[ 0.     ,  0.      ,  0.124001],
                           [ 0.     ,  0.941173, -0.289336],
                           [ 0.81508, -0.470587, -0.289336],
                           [-0.81508, -0.470587, -0.289336]]*Angstrom 
    )

calculator = HuckelCalculator()
molecule_configuration.setCalculator(calculator)

# Perform SCF loop
molecule_configuration.update()

# Save state
nlsave('nh3_scf.nc', molecule_configuration)

nh3_save.py

Restore the self-consistent state from a saved file, calculate the MolecularEnergySpectrum, and save it to the file spectrum.nc with object_id = 0. This will overwrite any data in the file spectrum.nc associated with the object_id.

# Read self-consistent calculation
molecule_configurations = nlread(
    'nh3_scf.nc',
    MoleculeConfiguration
    )
molecule_configuration = molecule_configurations[0]

# Calculate the molecular energy spectrum
spectrum = MolecularEnergySpectrum(molecule_configuration)

# Save the molecular energy spectrum
nlsave('spectrum.nc', spectrum, 'id0')

nh3_spectrum.py

Notes

The nc file is written in the NetCDF format. This is a platform independent format, and the files can for instance be written on a Linux platform and later be read on a Windows platform.

The content of the file can be converted to ASCII format with the command ncdump.

Each entry in the NetCDF file is associated with a unique id, object_id. If a new entry is saved without specifying a object_id, the entry is appended to the file with an auto-generated object_id. If a object_id is specified which already is present in the file, the old entry is automatically deleted.