Skip to content

Commit fb9f283

Browse files
committed
cli: use facilities from cp2k-input-tools 0.5+ to get coords
1 parent 7bd0998 commit fb9f283

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

aiida_cp2k/cli/data/structure.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"""Command line utilities to create and inspect `StructureData` nodes from CP2K input files."""
33

44
import re
5-
from fractions import Fraction
65

76
import click
87
import numpy as np
@@ -49,8 +48,9 @@ def cmd_import(filename, dry_run):
4948

5049
parser = CP2KInputParser()
5150
tree = parser.parse(filename)
51+
force_eval_no = -1
5252

53-
for force_eval in tree['+force_eval']:
53+
for force_eval_no, force_eval in enumerate(tree['+force_eval']):
5454
try:
5555
cell = force_eval['+subsys']['+cell']
5656
kinds = force_eval['+subsys']['+kind']
@@ -97,15 +97,9 @@ def cmd_import(filename, dry_run):
9797
if coord.get('units', 'angstrom').lower() != 'angstrom':
9898
echo.echo_critical('unit conversion for coordinates is not (yet) supported')
9999

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)))
109103

110104
formula = structure.get_formula()
111105

0 commit comments

Comments
 (0)