#!/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/>.
#*
#* **************************************************************************
import sys
from optparse import OptionParser
import numpy as np
import numpy.linalg as la
import CDTK.Tools.Utils as uti
[docs]
def start():
"""
Wrapper for starting the program. Needed for good unit test coding.
"""
# --------------------------------------------------------------------------
# Parse command line options
# --------------------------------------------------------------------------
parser=OptionParser()
parser.add_option('-a','--atomI',
dest='atomI',
type='int',
default=1,
help='atom i')
parser.add_option('-b','--atomJ',
dest='atomJ',
type='int',
default=2,
help='atom j')
opts, args = parser.parse_args(sys.argv[1:])
if not sys.argv[1:]: # called without any option
parser.print_help()
sys.exit(0)
# --------------------------------------------------------------------------
# Open output file
# --------------------------------------------------------------------------
sout = 'coord_' + str(opts.atomI) + '_' + str(opts.atomJ)
# --------------------------------------------------------------------------
# Read in times and positions
# --------------------------------------------------------------------------
t = uti.getTrajectoryTimeSteps('R.log')
Xt = uti.atomicCoordinatesFromRlog('R.log')
# --------------------------------------------------------------------------
# Calculate distance and write to output file
# --------------------------------------------------------------------------
ai = opts.atomI - 1
aj = opts.atomJ - 1
with open(sout,'w') as fout:
for i,tstep in enumerate(t):
rij = Xt[i][aj] - Xt[i][ai]
Rij = la.norm(rij)
fout.write('{0: >12.3f} {1: >10.5f}\n'.format(tstep,Rij) )
if __name__ == "__main__":
start()