Convert to ams.rkf trajectory with bond guessing

Note: This example requires AMS2023 or later.

To convert a trajectory from a different format to ams.rkf, you can for example use the below script.

This may be useful if you for example have a trajectory in VASP or .xyz format and want to use the AMS GUI to visualize the trajectory or run e.g. ChemTraYzer2 reaction analysis.

The bond guessing is done by running a “replay” job with engine LennardJones.

Example usage: (Download

#!/usr/bin/env amspython
import os

from scm.plams import *

def main():
    # the first argument needs to be a file readable by ASE
    original_trajectory = os.path.expandvars(
    convert_to_ams_rkf_with_bond_guessing(original_trajectory, "converted-to-ams.rkf")
    # convert_to_ams_rkf_with_bond_guessing('', 'converted-to-ams.rkf')

def convert_to_ams_rkf_with_bond_guessing(filename, outfile="out.rkf", task="moleculardynamics", timestep=0.5):
    temp_traj = "out.traj"
    file_to_traj(filename, temp_traj)
    traj_to_rkf(temp_traj, outfile, task=task, timestep=timestep)

    # config.log.stdout = 0
    # config.erase_workdir = True   # to remove workdir, only use this if you're not already inside another PLAMS workflow

    s = Settings()
    s.input.ams.task = "replay"
    s.input.ams.replay.file = os.path.abspath(outfile) = "yes" = "yes"
    s.runscript.nproc = 1
    job = AMSJob(settings=s, name="rep")
    cpkf = os.path.expandvars("$AMSBIN/cpkf")
    os.system(f'sh "{cpkf}" "{job.results.rkfpath()}" "{outfile}" History Molecules')


if __name__ == "__main__":