33import numpy as np
44
55import mala
6- from mala .datahandling .data_repo import data_path_be
6+ from mala .datahandling .data_repo import data_path_be , data_path_bao
7+
8+ accuracy_band_energy = 1
9+ accuracy_strict = 1e-16
710
811
912class TestSplitting :
@@ -96,9 +99,9 @@ def test_ldos_alignment(self):
9699 # initialize and add snapshots to workflow
97100 ldos_aligner = mala .LDOSAligner (parameters )
98101 ldos_aligner .clear_data ()
99- ldos_aligner .add_snapshot ("Be_snapshot0.out.npy" , data_path )
100- ldos_aligner .add_snapshot ("Be_snapshot1.out.npy" , data_path )
101- ldos_aligner .add_snapshot ("Be_snapshot2.out.npy" , data_path )
102+ ldos_aligner .add_snapshot ("Be_snapshot0.out.npy" , data_path_be )
103+ ldos_aligner .add_snapshot ("Be_snapshot1.out.npy" , data_path_be )
104+ ldos_aligner .add_snapshot ("Be_snapshot2.out.npy" , data_path_be )
102105
103106 # align and cut the snapshots from the left and right-hand sides
104107 ldos_aligner .align_ldos_to_ref (
@@ -107,6 +110,7 @@ def test_ldos_alignment(self):
107110
108111 try :
109112 import openpmd_api
113+
110114 use_openpmd = True
111115 except ImportError :
112116 use_openpmd = False
@@ -115,24 +119,95 @@ def test_ldos_alignment(self):
115119 # initialize and add snapshots to workflow
116120 ldos_aligner = mala .LDOSAligner (parameters )
117121 ldos_aligner .clear_data ()
118- ldos_aligner .add_snapshot ("Be_snapshot0.out.h5" ,
119- data_path , snapshot_type = 'openpmd' )
120- ldos_aligner .add_snapshot ("Be_snapshot1.out.h5" ,
121- data_path , snapshot_type = 'openpmd' )
122- ldos_aligner .add_snapshot ("Be_snapshot2.out.h5" ,
123- data_path , snapshot_type = 'openpmd' )
122+ ldos_aligner .add_snapshot (
123+ "Be_snapshot0.out.h5" , data_path_be , snapshot_type = "openpmd"
124+ )
125+ ldos_aligner .add_snapshot (
126+ "Be_snapshot1.out.h5" , data_path_be , snapshot_type = "openpmd"
127+ )
128+ ldos_aligner .add_snapshot (
129+ "Be_snapshot2.out.h5" , data_path_be , snapshot_type = "openpmd"
130+ )
124131
125132 # align and cut the snapshots from the left and right-hand sides
126133 ldos_aligner .align_ldos_to_ref (
127- left_truncate = True , right_truncate_value = 11 , number_of_electrons = 4
134+ left_truncate = True ,
135+ right_truncate_value = 11 ,
136+ number_of_electrons = 4 ,
128137 )
129138
130139 parameters = mala .Parameters ()
131140 data_handler = mala .DataHandler (parameters )
132141 for i in range (1 , 4 ):
133- data_openpmd = data_handler .target_calculator .read_from_openpmd_file (
134- f"{ data_path } /aligned/Be_snapshot0.out.h5" )
135- data_numpy = data_handler .target_calculator .read_from_numpy_file (
136- f"{ data_path } /aligned/Be_snapshot0.out.npy" )
142+ data_openpmd = (
143+ data_handler .target_calculator .read_from_openpmd_file (
144+ f"{ data_path_be } /aligned/Be_snapshot0.out.h5"
145+ )
146+ )
147+ data_numpy = (
148+ data_handler .target_calculator .read_from_numpy_file (
149+ f"{ data_path_be } /aligned/Be_snapshot0.out.npy"
150+ )
151+ )
137152 if not np .allclose (data_numpy , data_openpmd ):
138153 raise Exception ("Inconsistency in snapshot" , i )
154+
155+ def test_ldos_splitting_multiple_elements (self ):
156+ """
157+ Test that the LDOS splitting works both on LDOS and DOS level.
158+
159+ We compute the band energy with splitted and unsplitted DOS and
160+ compare both to splitted LDOS band energy.
161+ """
162+ params = mala .Parameters ()
163+
164+ params .targets .ldos_gridsize = [12 , 13 , 14 , 28 ]
165+ params .targets .ldos_gridspacing_ev = [0.5 , 0.5 , 0.5 , 0.5 ]
166+ params .targets .ldos_gridoffset_ev = [- 19 , - 10.5 , - 4.5 , 3.5 ]
167+ params .targets .pseudopotential_path = "."
168+
169+ dos_calculator = mala .DOS (params )
170+ dos_calculator .read_additional_calculation_data (
171+ os .path .join (data_path_bao , "BaO_snapshot0.out" )
172+ )
173+ dos_calculator .read_from_qe_out (
174+ os .path .join (data_path_bao , "BaO_snapshot0.out" ),
175+ smearing_factor = [2 , 2 , 2 , 2 ],
176+ )
177+
178+ params2 = mala .Parameters ()
179+ params2 .targets .ldos_gridsize = 73
180+ params2 .targets .ldos_gridspacing_ev = 0.5
181+ params2 .targets .ldos_gridoffset_ev = - 19
182+ params2 .targets .pseudopotential_path = "."
183+ dos_calculator_unsplitted = mala .DOS (params2 )
184+ dos_calculator_unsplitted .read_additional_calculation_data (
185+ os .path .join (data_path_bao , "BaO_snapshot0.out" )
186+ )
187+
188+ dos_calculator_unsplitted .read_from_qe_out (
189+ os .path .join (data_path_bao , "BaO_snapshot0.out" ),
190+ smearing_factor = 2 ,
191+ )
192+
193+ params3 = mala .Parameters ()
194+ params3 .targets .ldos_gridsize = [12 , 13 , 14 , 28 ]
195+ params3 .targets .ldos_gridspacing_ev = [0.5 , 0.5 , 0.5 , 0.5 ]
196+ params3 .targets .ldos_gridoffset_ev = [- 19 , - 10.5 , - 4.5 , 3.5 ]
197+
198+ ldos_calculator = mala .LDOS .from_numpy_file (
199+ params3 , os .path .join (data_path_bao , "BaO_snapshot0.out.npy" )
200+ )
201+ ldos_calculator .read_additional_calculation_data (
202+ os .path .join (data_path_bao , "BaO_snapshot0.info.json" )
203+ )
204+ assert np .isclose (
205+ dos_calculator .band_energy ,
206+ ldos_calculator .band_energy ,
207+ atol = accuracy_strict ,
208+ )
209+ assert np .isclose (
210+ dos_calculator .band_energy ,
211+ dos_calculator_unsplitted .band_energy ,
212+ atol = accuracy_band_energy ,
213+ )
0 commit comments