Source code for CDTK.cdtk2xyz

#!/usr/bin/env python
#*  **************************************************************************
#*
#*  CDTK, Chemical Dynamics Toolkit
#*  A modular system for chemical dynamics applications and more
#*
#*  Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016
#*  Oriol Vendrell, DESY, <oriol.vendrell@desy.de>
#*
#*  Copyright (C) 2017, 2018, 2019
#*  Ralph Welsch, DESY, <ralph.welsch@desy.de>
#*
#*  Copyright (C) 2020, 2021, 2022, 2023
#*  Ludger Inhester, DESY, ludger.inhester@cfel.de
#*
#*  This file is part of CDTK.
#*
#*  CDTK is free software: you can redistribute it and/or modify
#*  it under the terms of the GNU General Public License as published by
#*  the Free Software Foundation, either version 3 of the License, or
#*  (at your option) any later version.
#*
#*  This program is distributed in the hope that it will be useful,
#*  but WITHOUT ANY WARRANTY; without even the implied warranty of
#*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#*  GNU General Public License for more details.
#*
#*  You should have received a copy of the GNU General Public License
#*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#*
#*  **************************************************************************
"""
This module has several functions to transform coordinates and velocities obtained
from Gromacs calculation into suitable input files for CDTK. Use ``gmx2cdtk -h`` 
to find out how to use this program.


Basic units in GMX, please look at the following web.
https://manual.gromacs.org/documentation/2019/reference-manual/definitions.html#table-basicunits
  
1 Picoseconds = 41341.374575751 Atomic Unit Of Time
1 nm = 18.8973 Bohr
1 nm/ps = 18.8973/41341.374575751 Bohr/A.u = 0.00045710381413114194
1 nm/ps = 4.571038E-04 Bohr/A.u
"""

# TODO: Implement molecular dictionary as a data class (python 3.7+) or similar (python 2.7)

import subprocess
from optparse import OptionParser

import numpy as np
import CDTK.Tools.Conversion as cv
import CDTK.Tools.Utils as uti
import os

[docs] def get_arg(): parser = OptionParser() parser = OptionParser(usage="usage: %prog [options]") parser.add_option( "-t", "--output_traj_file", dest="trajFile", type="str", default="traj.xyz", help="output trajectory file (data from R.log)", ) parser.add_option( "-g", "--output_geom_file", dest="geomFile", type="str", default="geom.xyz", help="output geometry file (data from atompos)", ) opts, args = parser.parse_args() return opts
[docs] def start(): opts = get_arg() if os.path.exists('atomlist'): atomlist = uti.readColumnFile('atomlist') else: raise ValueError('atom list (./atomlist) not found') # - Atomic positions atompos if os.path.exists('atompos'): xcart = np.array( uti.readColumnFile('atompos'),float ) geom = np.array([xcart.reshape(-1,3)]) uti.traj2xyz(atomlist, geom, opts.geomFile, comment='data from atompos') # - Trajectory data R.log if os.path.exists('R.log'): t = uti.getTrajectoryTimeSteps('R.log') geom = uti.atomicCoordinatesFromRlog('R.log') uti.traj2xyz(atomlist, geom, opts.trajFile, comment='data from CDTK trajectory R.log', timesteps=t) else: print(f"R.log not found: skipping output of {opts.trajFile}")
if __name__ == "__main__": start()