|
2 | 2 | """Command line utilities to create and inspect `StructureData` nodes from CP2K input files.""" |
3 | 3 |
|
4 | 4 | import re |
5 | | -from fractions import Fraction |
6 | 5 |
|
7 | 6 | import click |
8 | 7 | import numpy as np |
@@ -49,8 +48,9 @@ def cmd_import(filename, dry_run): |
49 | 48 |
|
50 | 49 | parser = CP2KInputParser() |
51 | 50 | tree = parser.parse(filename) |
| 51 | + force_eval_no = -1 |
52 | 52 |
|
53 | | - for force_eval in tree['+force_eval']: |
| 53 | + for force_eval_no, force_eval in enumerate(tree['+force_eval']): |
54 | 54 | try: |
55 | 55 | cell = force_eval['+subsys']['+cell'] |
56 | 56 | kinds = force_eval['+subsys']['+kind'] |
@@ -97,15 +97,9 @@ def cmd_import(filename, dry_run): |
97 | 97 | if coord.get('units', 'angstrom').lower() != 'angstrom': |
98 | 98 | echo.echo_critical('unit conversion for coordinates is not (yet) supported') |
99 | 99 |
|
100 | | - for coordline in coord['*']: |
101 | | - # coordinates are a series of strings according to the CP2K schema |
102 | | - fields = coordline.split() |
103 | | - |
104 | | - name = fields[0] |
105 | | - # positions can be fractions AND they may be scaled |
106 | | - position = tmat @ np.array([float(Fraction(f)) for f in fields[1:4]]) |
107 | | - |
108 | | - structure.append_site(Site(kind_name=name, position=position)) |
| 100 | + for name, position, _ in parser.coords(force_eval_no): |
| 101 | + # positions can be scaled, apply transformation matrix |
| 102 | + structure.append_site(Site(kind_name=name, position=tmat @ np.array(position))) |
109 | 103 |
|
110 | 104 | formula = structure.get_formula() |
111 | 105 |
|
|
0 commit comments