1#!/usr/bin/env python 2 3# make new dump file by combining snapshots from multiple NEB replica dumps 4# Syntax: neb_combine.py -switch arg(s) -switch arg(s) ... 5# -o outfile = new dump file 6# each snapshot has NEB atoms from all replicas 7# -r dump1 dump2 ... = replica dump files of NEB atoms 8# can be in any order 9# -b dumpfile = background atoms (optional) 10# first snapshot in this file used as static non-NEB atoms 11 12import sys,os 13path = os.environ["LAMMPS_PYTHON_TOOLS"] 14sys.path.append(path) 15from dump import dump 16 17# parse args 18 19outfile = "" 20backfile = "" 21rfiles = [] 22 23argv = sys.argv 24iarg = 1 25narg = len(argv) 26while iarg < narg: 27 if argv[iarg] == "-o": 28 outfile = argv[iarg+1] 29 iarg += 2 30 elif argv[iarg] == "-b": 31 backfile = argv[iarg+1] 32 iarg += 2 33 elif argv[iarg] == "-r": 34 ilast = iarg + 1 35 while ilast < narg and argv[ilast][0] != '-': ilast += 1 36 rfiles = argv[iarg+1:ilast] 37 iarg = ilast 38 else: break 39 40if iarg < narg or not outfile or not rfiles: 41 print "Syntax: neb_combine.py -o outfile -b backfile -r dump1 dump2 ..." 42 sys.exit() 43 44if os.path.exists(outfile): os.remove(outfile) 45 46# ntotal = total atoms in each snapshot 47# reset IDs of atoms in each NEB dump file 48 49ntotal = 0 50d = [] 51for file in rfiles: 52 one = dump(file) 53 nnew = one.snaps[0].nselect 54 idvec = range(ntotal+1,ntotal+nnew+1) 55 one.setv("id",idvec) 56 ntotal += nnew 57 d.append(one) 58 59# nback = additional atoms in each snapshot 60# reset IDs of atoms in background file 61 62if backfile: 63 back = dump(backfile) 64 t = back.time() 65 back.tselect.one(t[0]) 66 nback = back.snaps[0].nselect 67 idvec = range(ntotal+1,ntotal+nback+1) 68 back.setv("id",idvec) 69else: nback = 0 70ntotal += nback 71 72# write out each snapshot 73# natoms = ntotal, by overwriting nselect 74# add background atoms if requested 75 76times = d[0].time() 77for time in times: 78 d[0].tselect.one(time) 79 i = d[0].findtime(time) 80 hold = d[0].snaps[i].nselect 81 d[0].snaps[i].nselect = ntotal 82 d[0].write(outfile,1,1) 83 d[0].snaps[i].nselect = hold 84 for one in d[1:]: 85 one.tselect.one(time) 86 one.write(outfile,0,1) 87 if backfile: back.write(outfile,0,1) 88 89