mirror of
https://github.com/arcan1s/moldyn.git
synced 2025-06-27 14:22:02 +00:00
add combine-qti
This commit is contained in:
104
combine-qti/combine-qti.py
Executable file
104
combine-qti/combine-qti.py
Executable file
@ -0,0 +1,104 @@
|
||||
#!/usr/bin/python2
|
||||
# combine-qti
|
||||
# Copyright (C) 2014 Evgeniy Alekseev <esalexeev@gmail.com>
|
||||
#
|
||||
# This program 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 argparse, os
|
||||
|
||||
|
||||
def readData(file):
|
||||
"""function to read data"""
|
||||
windows = 0
|
||||
data = []
|
||||
# preread
|
||||
with open (file, "r") as input:
|
||||
for line in input:
|
||||
if (line.split('\t')[0] == "<windows>"):
|
||||
windows = int(line.split('\t')[1].strip())
|
||||
with open (file, "r") as input:
|
||||
for window in range(windows):
|
||||
for line in input:
|
||||
if (line.strip() == "<table>"):
|
||||
data.append("<table>\n")
|
||||
break
|
||||
elif (line.strip() == "<multiLayer>"):
|
||||
data.append("<multiLayer>\n")
|
||||
break
|
||||
for line in input:
|
||||
if (line.strip() == '</table>'):
|
||||
data.append("</table>\n")
|
||||
break
|
||||
elif (line.strip() == '</multiLayer>'):
|
||||
data.append("</multiLayer>\n")
|
||||
break
|
||||
data.append(line)
|
||||
return windows, data
|
||||
|
||||
|
||||
def printHeader(file, windowsNum=1):
|
||||
"""function to print header"""
|
||||
iter = 0
|
||||
suffix = ""
|
||||
while (os.path.exists(file + suffix)):
|
||||
suffix = ".%i" % (iter)
|
||||
iter = iter + 1
|
||||
if (suffix != ""):
|
||||
os.rename(file, file + suffix)
|
||||
with open(file, "w") as output:
|
||||
output.write("QtiPlot 0.9.8 project file\n")
|
||||
output.write("<scripting-lang>\tPython\n")
|
||||
output.write("<windows>\t%i\n" % (windowsNum))
|
||||
|
||||
|
||||
def printData(file, data):
|
||||
"""function to print data"""
|
||||
with open(file, "a") as output:
|
||||
for line in data:
|
||||
output.write(line)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description = 'Combine several *.qti files into one')
|
||||
parser.add_argument('-d', '--directory', dest = 'dir',
|
||||
help = 'Directory with input files or use --input', action = 'store', default = False)
|
||||
parser.add_argument('-i', '--input', dest = 'input',
|
||||
help = 'Input files, comma separated', action = 'store', default = False)
|
||||
parser.add_argument('-o', '--output', dest = 'output',
|
||||
help = 'Output file', action = 'store', default = False)
|
||||
args = parser.parse_args()
|
||||
|
||||
input = []
|
||||
if (args.dir):
|
||||
if (os.path.isdir(args.dir)):
|
||||
input = [file for file in os.listdir(args.dir) if (os.path.splitext(file)[1] == ".qti")]
|
||||
else:
|
||||
if (args.input):
|
||||
for file in args.input.split(','):
|
||||
if (os.path.isfile(file)): input.append(file)
|
||||
output = args.output
|
||||
if (not input) or (not output):
|
||||
print ("Files are not set")
|
||||
exit()
|
||||
|
||||
totalWindows = 0
|
||||
totalData = []
|
||||
for file in input:
|
||||
windows, data = readData(file)
|
||||
totalWindows = totalWindows + windows
|
||||
totalData.append(data)
|
||||
printHeader(output, totalWindows)
|
||||
for data in totalData:
|
||||
printData(output, data)
|
@ -5,8 +5,8 @@ import argparse, math
|
||||
|
||||
def get_aver_dipole(dipole):
|
||||
"""function to get average dipole moment"""
|
||||
aver_dipole = math.sqrt((dipole[0] * dipole[0] +
|
||||
dipole[1] * dipole[1] +
|
||||
aver_dipole = math.sqrt((dipole[0] * dipole[0] +
|
||||
dipole[1] * dipole[1] +
|
||||
dipole[2] * dipole[2]))
|
||||
aver_dipole = round(aver_dipole, 4)
|
||||
return aver_dipole
|
||||
@ -56,15 +56,15 @@ if __name__ == "__main__":
|
||||
parser.add_argument('-v', '--vector', dest = 'vector',
|
||||
help = 'Return vector', action = 'store_true', default = False)
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
if ((not args.input) or (not args.coord)):
|
||||
print "Input files are not set"
|
||||
exit
|
||||
|
||||
exit()
|
||||
|
||||
charges = get_charges(args.input)
|
||||
coords = get_coordinates(args.coord)
|
||||
if (args.vector):
|
||||
print get_dipole(charges, coords)
|
||||
else:
|
||||
print get_aver_dipole(get_dipole(charges, coords))
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user