#!/usr/bin/python import sys # Fisrt command line argument is the name of the xyz file xyzfile=open(sys.argv[1],'r') # Second command line argument is the name of the file with the partial charges chargefile=open(sys.argv[2],'r') total_atoms=int(xyzfile.readline()) charges=[0 for i in range(total_atoms)] charges2=[0 for i in range(total_atoms)] for i in range(0,5): chargeline=chargefile.readline() for i in range(0,total_atoms): chargeline=chargefile.readline() tokens=chargeline.split() charges[i]=float(tokens[1]) y1=float(sys.argv[3]) y2=float(sys.argv[4]) x1=float(min(charges)) x2=float(max(charges)) print 'min value={} max value={}'.format(x1,x2) m=(y1-y2)/(x1-x2) b=y1-m*x1 print 'm={} b={}'.format(m,b) for i in range(0,total_atoms): charges2[i]=m*charges[i]+b print 'charge {} is {} original, new is {}'.format(i,charges[i],charges2[i]) outfile=open(sys.argv[5],'w') outfile.write('{}\n'.format(total_atoms)) outfile.write(xyzfile.readline()) for i in range(0,total_atoms): xyzline=xyzfile.readline() tokens=xyzline.split() outfile.write(' {} {} {} {} {}\n'.format(tokens[0],tokens[1],tokens[2],tokens[3],charges2[i]))