@@ -83,3 +83,56 @@ def test_dos_splitting(self):
8383 )
8484 )
8585 )
86+
87+ # This test is based on examples/advanced/ex09_align_ldos.py, but adds a
88+ # test to check that the aligned data is equivalent between the numpy-based
89+ # and the openPMD-based implementations.
90+ def test_ldos_alignment (self ):
91+ parameters = mala .Parameters ()
92+ parameters .targets .ldos_gridoffset_ev = - 5
93+ parameters .targets .ldos_gridsize = 11
94+ parameters .targets .ldos_gridspacing_ev = 2.5
95+
96+ # initialize and add snapshots to workflow
97+ ldos_aligner = mala .LDOSAligner (parameters )
98+ 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+
103+ # align and cut the snapshots from the left and right-hand sides
104+ ldos_aligner .align_ldos_to_ref (
105+ left_truncate = True , right_truncate_value = 11 , number_of_electrons = 4
106+ )
107+
108+ try :
109+ import openpmd_api
110+ use_openpmd = True
111+ except ImportError :
112+ use_openpmd = False
113+
114+ if use_openpmd :
115+ # initialize and add snapshots to workflow
116+ ldos_aligner = mala .LDOSAligner (parameters )
117+ 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' )
124+
125+ # align and cut the snapshots from the left and right-hand sides
126+ ldos_aligner .align_ldos_to_ref (
127+ left_truncate = True , right_truncate_value = 11 , number_of_electrons = 4
128+ )
129+
130+ parameters = mala .Parameters ()
131+ data_handler = mala .DataHandler (parameters )
132+ 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" )
137+ if not np .allclose (data_numpy , data_openpmd ):
138+ raise Exception ("Inconsistency in snapshot" , i )
0 commit comments