-
Notifications
You must be signed in to change notification settings - Fork 1
/
amsedit.py
executable file
·51 lines (40 loc) · 1.44 KB
/
amsedit.py
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
#!/usr/bin/env python3
import argparse
# Parse command line arguments
desc = 'Perform some manipulations on ams files'
parser = argparse.ArgumentParser(description=desc,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('infiles', type=str, nargs='*', default=[],
help='Ams file to parse.')
parser.add_argument('-P', '--eplot', action='store_true', default=False,
help='Planarize a structure.')
opts = parser.parse_args()
class AMSmatrix:
def __init__(self, fn):
self.zmat = self._parseams(fn)
def _parseams(self, fn):
_lines = []
with open(fn, 'rt') as fh:
for _l in fh:
_lines.append(_l.strip())
in_atoms = False
natoms = 0
atoms = {}
for i, _l in enumerate(_lines):
if _l == 'Number of atoms':
natoms = int(_lines[i+1].split(' ')[1])
if _l == 'Atom data':
in_atoms = True
continue
if _l == 'DUMMYELEMENT':
in_atoms = False
continue
if in_atoms:
_atom = _l.split(',')
_idx = int(_atom[1])
if _idx not in atoms:
_atoms[_idx] = []
print(f'Found {natoms} atoms in {fn}')
zmats = []
for in_file in opts.infiles:
zmats.append(AMSmatrix(in_file))