Skip to content

Commit cc04034

Browse files
committed
write_atoms test
1 parent 1f60741 commit cc04034

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

asimtools/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ def write_atoms(
204204
if len(atoms.constraints) > 0:
205205
columns.append('move_mask')
206206

207+
if 'initial_magmoms' in columns:
208+
for atoms in images:
209+
atoms.arrays['initial_magmoms'] = np.where(
210+
np.isnan(atoms.arrays['initial_magmoms']),
211+
0,
212+
atoms.arrays['initial_magmoms'],
213+
)
214+
207215
write(
208216
image_file,
209217
images,

tests/data/structures/adslab.xyz

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
55
2+
Lattice="10.989862374024527 0.0 6.729349889709534e-16 -3.6632874580081776 10.361341611972845 6.729349889709536e-16 0.0 0.0 29.910616844190965" Properties=species:S:1:pos:R:3:initial_magmoms:R:1:surface_properties:S:1:bulk_wyckoff:S:1:bulk_equivalent:S:1:move_mask:L:1 pbc="T T T"
3+
Na 0.00000000 0.00000000 4.48659253 nan subsurface a 0 F
4+
Na -1.22109582 3.45378054 4.48659253 nan subsurface a 0 F
5+
Na -2.44219164 6.90756107 4.48659253 nan subsurface a 0 F
6+
Na 3.66328746 0.00000000 4.48659253 nan subsurface a 0 F
7+
Na 2.44219164 3.45378054 4.48659253 nan subsurface a 0 F
8+
Na 1.22109582 6.90756107 4.48659253 nan subsurface a 0 F
9+
Na 7.32657492 0.00000000 4.48659253 nan subsurface a 0 F
10+
Na 6.10547910 3.45378054 4.48659253 nan subsurface a 0 F
11+
Na 4.88438328 6.90756107 4.48659253 nan subsurface a 0 F
12+
Na 1.22109582 1.72689027 1.49553084 nan subsurface a 0 F
13+
Na -0.00000000 5.18067081 1.49553084 nan subsurface a 0 F
14+
Na -1.22109582 8.63445134 1.49553084 nan subsurface a 0 F
15+
Na 4.88438328 1.72689027 1.49553084 nan subsurface a 0 F
16+
Na 3.66328746 5.18067081 1.49553084 nan subsurface a 0 F
17+
Na 2.44219164 8.63445134 1.49553084 nan subsurface a 0 F
18+
Na 8.54767074 1.72689027 1.49553084 nan subsurface a 0 F
19+
Na 7.32657492 5.18067081 1.49553084 nan subsurface a 0 F
20+
Na 6.10547910 8.63445134 1.49553084 nan subsurface a 0 F
21+
Na 0.05040356 0.07128126 10.61153565 nan subsurface a 0 T
22+
Na -1.22088381 3.45363060 10.47942977 nan subsurface a 0 T
23+
Na -2.43700358 6.91641549 10.46332553 nan subsurface a 0 T
24+
Na 3.66307537 0.00014975 10.47942998 nan subsurface a 0 T
25+
Na 2.39178795 3.38249920 10.61153531 nan subsurface a 0 T
26+
Na 1.21590808 6.89870710 10.46332525 nan subsurface a 0 T
27+
Na 7.33319379 0.00784251 10.46332545 nan subsurface a 0 T
28+
Na 6.09886082 3.44593812 10.46332545 nan subsurface a 0 T
29+
Na 4.88438293 6.90756134 10.52503220 nan subsurface a 0 T
30+
Na 1.22109579 1.72689044 7.49352623 nan subsurface a 0 T
31+
Na 0.00009148 5.17841763 7.48202082 nan subsurface a 0 T
32+
Na -1.22118690 8.63670456 7.48202064 nan subsurface a 0 T
33+
Na 4.88222840 1.72622555 7.48202032 nan subsurface a 0 T
34+
Na 3.66029354 5.17643697 7.50198302 nan subsurface a 0 T
35+
Na 2.44173987 8.63477030 7.48098737 nan subsurface a 0 T
36+
Na 8.54982542 1.72755533 7.48202044 nan subsurface a 0 T
37+
Na 7.32702677 5.18035170 7.48098729 nan subsurface a 0 T
38+
Na 6.10847301 8.63868512 7.50198293 nan subsurface a 0 T
39+
Na -0.05716541 -0.08084452 16.64749813 nan surface a 0 T
40+
Na -0.66173064 3.05824944 16.35385328 nan surface a 0 T
41+
Na -2.36879258 6.61089299 16.32311991 nan surface a 0 T
42+
Na 3.10392211 0.39553082 16.35385370 nan surface a 0 T
43+
Na 2.49935741 3.53462570 16.64749940 nan surface a 0 T
44+
Na 1.14769723 7.20422919 16.32311967 nan surface a 0 T
45+
Na 7.02240734 -0.02968818 16.32312005 nan surface a 0 T
46+
Na 6.40964675 3.48346858 16.32312000 nan surface a 0 T
47+
Na 4.88438260 6.90756112 16.41278280 nan surface a 0 T
48+
Na 1.22109540 1.72689040 13.93937426 nan subsurface a 0 T
49+
Na -0.06036830 5.24521596 13.41401878 nan subsurface a 0 T
50+
Na -1.16072730 8.56990626 13.41401807 nan subsurface a 0 T
51+
Na 4.96535977 1.69148936 13.41401871 nan subsurface a 0 T
52+
Na 3.64865650 5.15997986 13.52384317 nan subsurface a 0 T
53+
Na 2.48037426 8.60745143 13.39723386 nan subsurface a 0 T
54+
Na 8.46669414 1.76229130 13.41401834 nan subsurface a 0 T
55+
Na 7.28839235 5.20767012 13.39723382 nan subsurface a 0 T
56+
Na 6.12011011 8.65514262 13.52384285 nan subsurface a 0 T
57+
O 1.22109586 1.72688973 16.17505098 2.00000000 adsorbate None None T

tests/unit/test_utils.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pathlib import Path
55
import os
66
import pytest
7+
import numpy as np
78
from ase.io import read
89
from pymatgen.core import Structure, Molecule, IStructure, IMolecule
910
from asimtools.utils import (
@@ -60,7 +61,7 @@ def test_join_names(test_input, expected):
6061
ase.build.fcc111('Al', size=(2,2,3))),
6162
({'image_file': STRUCT_DIR / 'Ar.xyz'},
6263
ase.build.bulk('Ar')),
63-
({'image_file': STRUCT_DIR / 'Ar', 'format': 'cfg'},
64+
({'image_file': STRUCT_DIR / 'Ar.xyz'},
6465
ase.build.bulk('Ar')),
6566
({'atoms': ase.build.bulk('Ar')}, ase.build.bulk('Ar')),
6667
({
@@ -126,6 +127,7 @@ def test_join_names(test_input, expected):
126127
coords=[[0, 0, 0], [1.5, 1.5, 1.5], [1.5, -1.5, -1.5]],
127128
spin_multiplicity=1,
128129
)),
130+
129131
])
130132
def test_get_atoms(test_input, expected):
131133
''' Test getting atoms from different inputs '''
@@ -173,6 +175,16 @@ def test_get_images(test_input, expected):
173175
for image in input_images:
174176
assert image in expected
175177

178+
def test_write_atoms(tmp_path):
179+
''' Test write_atoms.
180+
Also test that when magmoms are provided by ASE which makes them nans
181+
and kills jobs using VASP etc., we change them to zero '''
182+
slab_ = read(STRUCT_DIR / 'adslab.xyz')
183+
write_atoms(tmp_path / 'slab.xyz', slab_)
184+
slab = read(tmp_path / 'slab.xyz')
185+
assert not np.any(np.isnan(slab.arrays['initial_magmoms']))
186+
assert 'surface_properties' in slab.arrays
187+
176188
@pytest.mark.parametrize("test_input, expected",[
177189
(['l1', 'l2', 'l3'], {'l1': {'l2': {'l3': 'new_value'}}}),
178190
(['l1', 'l2'], {'l1': {'l2': 'new_value'}}),

0 commit comments

Comments
 (0)