def test_nc_EDM_non_colinear(sisl_tmp): EDM1 = EnergyDensityMatrix(sisl.geom.graphene(), spin=sisl.Spin('NC')) EDM1.construct(([0.1, 1.44], [0.1, 0.2, 0.3, 0.4])) f1 = sisl_tmp('EDM1.nc', _dir) f2 = sisl_tmp('EDM2.nc', _dir) EDM1.write(f1) EDM1.finalize() EDM2 = sisl.get_sile(f1).read_energy_density_matrix() EDM2.write(f2) EDM3 = sisl.get_sile(f2).read_energy_density_matrix() assert EDM1._csr.spsame(EDM2._csr) assert np.allclose(EDM1._csr._D, EDM2._csr._D) assert EDM1._csr.spsame(EDM3._csr) assert np.allclose(EDM1._csr._D, EDM3._csr._D)
def test_read_write_energy_density_matrix(self, sisl_tmp, sisl_system, sile): G = sisl_system.g.rotatec(-30) EDM = EnergyDensityMatrix(G, orthogonal=True) EDM.construct([[0.1, 1.45], [0.1, -2.7]]) f = sisl_tmp('test_read_write_energy_density_matrix.win', _dir) # Write sile(f, mode='w').write_energy_density_matrix(EDM) # Read 1 try: edm = sile(f, mode='r').read_energy_density_matrix(geometry=EDM.geom) assert EDM.spsame(edm) except UnicodeDecodeError as e: pass # Read 2 try: edm = EnergyDensityMatrix.read(sile(f, mode='r'), geometry=EDM.geom) assert EDM.spsame(edm) except UnicodeDecodeError as e: pass
def test_nc_EDM_non_colinear(sisl_tmp): EDM1 = EnergyDensityMatrix(sisl.geom.graphene(), spin=sisl.Spin('NC')) EDM1.construct(([0.1, 1.44], [[0.1, 0.2, 0.3, 0.4], [0.2, 0.3, 0.4, 0.5]])) f1 = sisl_tmp('EDM1.nc', _dir) f2 = sisl_tmp('EDM2.nc', _dir) EDM1.write(f1, sort=False) EDM1.finalize() EDM2 = sisl.get_sile(f1).read_energy_density_matrix(sort=False) EDM2.write(f2, sort=False) EDM3 = sisl.get_sile(f2).read_energy_density_matrix(sort=False) assert EDM1._csr.spsame(EDM2._csr) assert EDM1._csr.spsame(EDM3._csr) # EDM1 is finalized, but EDM2 is not finalized assert not np.allclose(EDM1._csr._D, EDM2._csr._D) # EDM2 and EDM3 are the same assert np.allclose(EDM2._csr._D, EDM3._csr._D) EDM2.finalize() assert np.allclose(EDM1._csr._D, EDM2._csr._D)