2. Input/output

2.1. Tools to read data from general packages

2.1.1. CHARMM

tamkin.io.charmm.load_molecule_charmm(charmmfile_cor, charmmfile_hess, is_periodic=False)

Read from Hessian-CHARMM-file format

Parameters:
  • charmmfile_cor -- the filename of the .cor file (|) –
  • charmmfile_hess -- the filename of the Hessian file (|) –
Optional argument:
is_periodic – True when the system is periodic in three dimensions. False when the systen is aperiodic. [default=True]
tamkin.io.charmm.load_coordinates_charmm(filename)

Read coordinates from a standard CHARMM coordinate file

Parameters:filename -- the CHARMM coordinate file (typically extension .crd or (|) – .cor)
Return values:
coordinates – coordinates in atomic units, numpy array with shape (N,3)
masses – atomic masses in atomic units
symbols – list of CHARMM atom symbols
tamkin.io.charmm.load_modes_charmm(filename)

Read modes, frequencies and masses from a standard CHARMM-modes-file

The CHARMM-modes-file is generated by the VIBRAN module in CHARMM.

Argument:
filename – CHARMM-modes-file
Return values:
modes – numpy array with mass-weighted modes in the columns
freqs – numpy array with frequencies in atomic units
masses – atomic masses in atomic units
tamkin.io.charmm.load_peptide_info_charmm(filename)

Load information from CHARMM file for peptide blocks and subsystems

Parameters:filename -- the CHARMM coordinate file (typically extension .crd (|) – or .cor)
Return values:
N – total number of atoms in the peptide
calpha – indices of the alpha carbons (‘CA’ in CHARMM file)
proline – indices of the alpha carbons that belong to proline residues (‘PRO CA’ in CHARMM file)
carbon – indices of the backbone carbons, exclude the alpha carbons (‘C’ in CHARMM file)
oxygen – indices of the backbone oxygens (‘O’ in CHARMM file)
nitrogen – indices of the backbone nitrogens (‘N’ in CHARMM file)

2.1.2. CP2K

tamkin.io.cp2k.load_molecule_cp2k(fn_sp, fn_freq, multiplicity=1, is_periodic=True)

Load a molecule with the Hessian from a CP2K computation

Parameters:
  • fn_sp -- The filename of the single point .out file containing the (|) – energy and the forces.
  • fn_freq -- The filename of the frequency .out file containing the (|) – hessian
Optional arguments:
multiplicity – The spin multiplicity of the electronic system [default=1]
is_periodic – True when the system is periodic in three dimensions. False when the systen is aperiodic. [default=True]
unit_cell – The unit cell vectors for periodic structures
tamkin.io.cp2k.load_fixed_cp2k(fn_freq)

Load the fixed atoms from a CP2K freq output

Parameters:fn_freq (str) – The filename of the CP2K freq output
Returns:fixed – The length of the vector corresponds to the number of atoms. For every fixed atom, the vector element is True. False otherwise.
Return type:numpy bool array

2.1.3. CPMD

tamkin.io.cpmd.load_molecule_cpmd(fn_out, fn_geometry, fn_hessian, multiplicity=1, is_periodic=True)

Load a molecule with the Hessian from a CPMD computation

Parameters:
  • fn_out -- The filename of the output containing the total energy. (|) –
  • fn_geometry -- The filename of geometry and the gradient of the (|) – (partially) optimized system. (This filename is typically GEOMETRY.xyz.)
  • fn_hessian -- The filename of the of the file containing the (|) – Hessian. (This filename is typically MOLVIB.)
Optional arguments:
multiplicity – The spin multiplicity of the electronic system [default=1]
is_periodic – True when the system is periodic in three dimensions. False when the system is aperiodic. [default=True]

2.1.4. Gaussian 03/09

tamkin.io.gaussian.load_fixed_g03com(filename)

Load fixed atoms from a gaussian input file.

Argument:
filename – The gaussian input file.

A fixed atom is recognized by the ‘-1’ after the atom symbol in the molecule specification. The ‘-1’ is the second word in the line.

tamkin.io.gaussian.load_molecule_g03fchk(fn_freq, fn_ener=None, fn_vdw=None, energy=None, fn_punch=None)

Load a molecule from Gaussian03 formatted checkpoint files.

Parameters:fn_freq -- the formatted checkpoint file of the frequency job (|) –
Optional arguments:
fn_ener – the formatted checkpoint file of a single point computation for the energy. When not given, the energy is taken from the frequency job.
fn_vdw – An orca output file containing a Van der Waals correction for the energy.
energy – Override the energy from the formatted checkpoint file with the given value.
punch – A Gaussian derivatives punch file. When given, the gradient and the Hessian are read from this file instead.
tamkin.io.gaussian.load_molecule_g98fchk(fn_freq, fn_ener=None, energy=None)

Load a molecule from Gaussian98 formatted checkpoint files.

Parameters:fn_freq -- The formatted checkpoint file of the frequency job. (|) –
Optional arguments:
fn_ener – The formatted checkpoint file of a single point computation for the energy. When not given, the energy is taken from the frequency job.
energy – Override the energy from the formatted checkpoint file with the given value.
tamkin.io.gaussian.load_rotscan_g03log(fn_log, top_indexes=None)

Load the torsional potential from a Gaussian 03 log/output file.

Argument:
fn_log – The filename of the gaussian output.
Optional argument:
top_indexes – The atom indexes that define the rotor. These do not have to include the atoms that define the rotational axis. When not given, an attempt is made to derive this information from the dihedral angle used for the scan.

2.1.5. QChem

tamkin.io.qchem.load_molecule_qchem(qchemfile, hessfile=None, multiplicity=1, is_periodic=False)

Load a molecule from a Q-Chem frequency run

Parameters:qchemfile -- Filename of the Q-Chem computation output. (|) –
Optional arguments:
hessfile – Filename of a separate Hessian file.
multiplicity – The spin multiplicity of the electronic system [default=1]
is_periodic – True when the system is periodic in three dimensions. False when the systen is nonperiodic. [default=False]

Whether the Hessian is printed to a separate Hessian file, depends on the used version of Q-Chem. The use of the separate Hessian file is slightly more accurate, because the number of printed digits is higher than in the Q-Chem output file.

Warning

At present, the gradient is set to a Nx3 array of zero values, since the gradient is not printed out in the Q-Chem output file in general. This means that the value of the gradient should be checked before applying methods designed for partially optimized structures (currently PHVA, MBH and PHVA_MBH).

2.1.6. VASP

tamkin.io.vasp.load_molecule_vasp(contcar, outcar_freq, outcar_energy=None, energy=None, multiplicity=1, is_periodic=True)

Load a molecule from VASP 4.6.X and 5.3.X output files

Parameters:
  • contcar -- A CONTCAR file with the structure used as POSCAR file for the (|) – Hessian/frequency calculation in VASP. Do not use the CONTCAR file generated by the frequency calculation. Use the CONTCAR from the preceding geometry optimization instead.
  • outcar_freq -- The OUTCAR file of the Hessian/frequency calculation. Also the (|) – gradient and the energy are read from this file. The energy without entropy (but not the extrapolation to sigma=0) is used.
Optional arguments:
outcar_energy – When given, the (first) energy without entropy is read from this file (not the extrapolation to sigma=0) instead of reading the energy from the freq output
energy – The potential energy, which overrides the contents of outcar_freq.
multiplicity – The spin multiplicity of the electronic system [default=1]
is_periodic – True when the system is periodic in three dimensions. False when the systen is nonperiodic. [default=True].
tamkin.io.vasp.load_fixed_vasp(filename)

Load list of fixed atoms from VASP output file

Argument:
filename – Filename of VASP output file (OUTCAR)

VASP can calculate partial Hessians: only a submatrix of the complete Hessian is computed with numerical differentiation. The rest of the Hessian elements is put to zero. This function determines which atoms have zero rows/cols in the Hessian, or, in other words, which were fixed.

2.2. File formats specific for TAMkin

tamkin.io.internal.load_chk(filename)

Load a TAMKin checkpoint file

Argument:
filename – the file to load from

The return value is a dictionary whose keys are field labels and the values can be None, string, integer, float, boolean or an array of strings, integers, booleans or floats.

The file format is similar to the Gaussian fchk format, but has the extra feature that the shapes of the arrays are also stored.

tamkin.io.internal.dump_chk(filename, data)

Dump a TAMKin checkpoint file

Argument:
filename – the file to write to
data – a dictionary whose keys are field labels and the values can be None, string, integer, float, boolean, an array/list of strings, integers, floats or booleans.

The file format is similar to the Gaussian fchk format, but has the extra feature that the shapes of the arrays are also stored.

tamkin.io.internal.load_indices(filename, shift=None, groups=False)

Load atom indexes from file

Individual atom indices are separated by white space or by one new-line character. Ranges of atoms can be specified in two ways:

  • [N1,N2]: the range includes N2 (Fortranish).
  • [N1,N2[: the range does not include N2 (Pythonic).

The atom indexes can be separated by one or more empty lines to define groups of atoms that belong toghether in one block. (See the groups argument.)

Parameters:filename -- The file to load the indexes from (|) –
Optional arguments:
shift – A constant shift applied to all atom indexes to convert between numbers starting from zero and numbers starting from one. When not given, the file is searched from a line beginning with #shift=, where the value after this prefix is used as translation to bring the indices back to C convention. Only the first occurence is parsed. If such line is not present, Fortran convention is assumed (shift=-1).
groups – When True, the function always returns a list of lists, even when only one group of indexes is found in the file. Otherwise only a single list of indexes is returned, even when multiple groups of indexes are encountered.
tamkin.io.internal.dump_indices(filename, indices, shift=1, compact=True)

Dump atom indexes to file

Parameters:filename -- the file to dump the atom indexes to (|) –
Optional arguments:
indices – a list of atom indices or a list of lists of atom indices (the latter is used to define blocks of atoms)
shift – A constant shift applied to all atom indexes to convert between numbers starting from zero and numbers starting from one.
compact – When True, the numbers belonging to the same block are put on one line, otherwise they are separated by a newline character. Different blocks are separated by an empty line. [default=True]

2.3. Tools to generate trajectories

tamkin.io.trajectory.dump_modes_xyz(nma, indexes=0, prefix='mode', amplitude=9.44863066960626, frames=36)

Write XYZ trajectory file(s) that vizualize internal mode(s)

Parameters:nma -- an object that specifies the normal modes, several formats (|) – are supported: (i) a Tamkin NMA object, (ii) a 3-tuple with reference coordinates, mass-unweighted mode(s) and atom numbers or (iii) a 4-tuple with reference coordinates, mass- weighted mode(s), atom numbers and a masses3 vector. the latter is a vector with 3*N elements containing the masses of the atoms in groups of three.
Optional arguments:
indexes – the index or a list of indexes of modes that must be written to trajectory files [default=0]
prefix – a prefix used for the output files. the generated trajectory filenames have the format prefix.index.xyz [default=”mode”]
amplitude – the amplitude of the normal mode vibration in atomic untis [default=5*angstrom]
frames – the number of frames written to the trajectory file [default=36]
tamkin.io.trajectory.dump_modes_molden(filename, nma, selected=None)

Write freqs and modes to a file in the Gaussian log format.

Parameters:
  • filename -- modes are written to this file, (|) – can be read by Molden (visualization program)
  • nma -- an NMA object or a tuple or list with five elements (|) – modes, frequencies, masses, numbers, coordinates. See _make_moldenfile for details.
Optional argument:
selected – Selection of modes for which to make trajectories. This can be a list or array of mode indices (length <= N), or an array of booleans (length = N).

The output file will look like a stripped Gaussian03 or Gaussian09 log file. It is sufficient to visualize the modes in Molden, Openbabel or Avogadro.

tamkin.io.trajectory.dump_modes_gaussian(filename, nma, selected=None)

Write freqs and modes to a file in the Gaussian log format.

Parameters:
  • filename -- modes are written to this file, (|) – can be read by Molden (visualization program)
  • nma -- an NMA object or a tuple or list with five elements (|) – modes, frequencies, masses, numbers, coordinates. See _make_moldenfile for details.
Optional argument:
selected – Selection of modes for which to make trajectories. This can be a list or array of mode indices (length <= N), or an array of booleans (length = N).

The output file will look like a stripped Gaussian03 or Gaussian09 log file. It is sufficient to visualize the modes in Molden, Openbabel or Avogadro.