-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathconversionTools
More file actions
executable file
·72 lines (61 loc) · 2.08 KB
/
conversionTools
File metadata and controls
executable file
·72 lines (61 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
import control as ctrl
import optparse
import sys
import os
# create a parser for the argv[]
parser = optparse.OptionParser()
parser.add_option('-i',
action='store',
dest='iFile',
default='olcao.skl',
help='''
The input file. Default is "olcao.skl".''')
parser.add_option('-o',
action='store',
dest='oFile',
default='new.olcao.skl',
help='''
The output file. Default is "new.olcao.skl".''')
parser.add_option('-c',
action='store_true',
dest='convCoors',
default=False,
help='''
Convert coordinates from cart to frac and vice versa. The default is to not
do any conversion.''')
parser.add_option('-b',
action='store',
dest='buf',
default=0.0,
type='float',
help='''
The buffer that is needed when reading or writing *.xyz files. This buffer will
pad the structure on all sides, and is needed for molecular systems. Default is
0.0 (no padding).''')
# parse the arguments
options, args = parser.parse_args()
out_extension = os.path.splitext(options.oFile)[1]
if out_extension != ".skl" and out_extension != ".xyz" and out_extension != ".lmp":
sys.exit("Sorry, Can only write to *.skl or *.xyz or *.lmp files currently.")
in_extension = os.path.splitext(options.iFile)[1]
if in_extension == ".xyz":
s = ctrl.Structure(options.iFile, buf=options.buf)
else:
s = ctrl.Structure(options.iFile)
# convert
if options.convCoors:
if s.coordType == "F":
s.toCart()
elif s.coordType == "C":
s.toFrac()
else:
sys.exit("unknow coordinate type: " + s.coordType)
if out_extension == ".skl":
s.writeSkl(fileName = options.oFile)
elif out_extension == ".xyz":
s.writeXyz(fileName = options.oFile)
elif out_extension == ".lmp":
s.writeLAMMPS(fileName = options.oFile)
else:
print "Dont know how to print this output file" + options.oFile