def test_cation_anion_mode_without_ions(self): with self.assertRaises(ValueError) as err: test = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "../ICOHPLIST.lobster"), structure=Structure.from_file( os.path.join(test_dir_env, "../POSCAR")), valences_from_charges=False, additional_condition=1, ) self.assertEqual( str(err.exception), "Valences cannot be assigned, additional_conditions 1 and 3 and 5 and 6 will not work" ) with self.assertRaises(ValueError) as err: test = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "../ICOHPLIST.lobster"), structure=Structure.from_file( os.path.join(test_dir_env, "../POSCAR")), valences_from_charges=False, additional_condition=1, valences=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], ) self.assertEqual( str(err.exception), "All valences are equal to 0, additional_conditions 1 and 3 and 5 and 6 will not work" )
def test_get_sum_icohps_between_neighbors_of_atom(self): # will only look at icohps between cations or anions self.chemenvlobster1.get_info_icohps_to_neighbors(isites=[1]) self.assertEqual( self.chemenvlobster1.get_info_icohps_between_neighbors( isites=[1])[2], 1) self.assertAlmostEqual( self.chemenvlobster1.get_info_icohps_between_neighbors( isites=[1])[0], -0.05507) self.assertEqual( self.chemenvlobster1.get_info_icohps_between_neighbors( isites=[0])[2], 15) # use an example where this is easier to test (e.g., linear environment?) chemenv_here = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp-7000.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp-7000.gz")), additional_condition=1, ) self.assertEqual( len(chemenv_here.get_info_icohps_between_neighbors(isites=[0])[4]), 6)
def test_set_limits(self): test = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_353"), structure=Structure.from_file(os.path.join(test_dir_env, "POSCAR.mp_353")), valences_from_charges=True, filename_CHARGE=os.path.join(test_dir_env, "CHARGE.lobster.mp-353.gz"), additional_condition=1, limits=[-100000, 0], )
def test_wrong_additional_correction(self): with self.assertRaises(ValueError): test = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_353"), structure=Structure.from_file(os.path.join(test_dir_env, "POSCAR.mp_353")), valences_from_charges=True, filename_CHARGE=os.path.join(test_dir_env, "CHARGE.lobster.mp-353.gz"), additional_condition=10, )
def test_get_info_cohps_to_neighbors(self): chemenvlobster1 = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_190_2.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_190.gz")), additional_condition=1, ) self.assertEqual( chemenvlobster1.get_info_cohps_to_neighbors( path_to_COHPCAR=os.path.join(test_dir_env, "COHPCAR.lobster.mp-190.gz"), isites=[0], only_bonds_to=["O"])[0], "6 x O-Re (per bond)", ) self.assertEqual( type( chemenvlobster1.get_info_cohps_to_neighbors( path_to_COHPCAR=os.path.join(test_dir_env, "COHPCAR.lobster.mp-190.gz"), isites=[0], only_bonds_to=["O"], )[1]), Cohp, ) cophthing = chemenvlobster1.get_info_cohps_to_neighbors( path_to_COHPCAR=os.path.join(test_dir_env, "COHPCAR.lobster.mp-190.gz"), isites=[0], only_bonds_to=None, per_bond=False, )[1] self.assertAlmostEqual( np.sum([cophthing.icohp[Spin.up], cophthing.icohp[Spin.down]], axis=0)[300], chemenvlobster1.get_info_icohps_to_neighbors(isites=[0])[0], ) # summed_spin_channel cophthing = chemenvlobster1.get_info_cohps_to_neighbors( path_to_COHPCAR=os.path.join(test_dir_env, "COHPCAR.lobster.mp-190.gz"), isites=[0], only_bonds_to=None, per_bond=False, summed_spin_channels=True, )[1] self.assertAlmostEqual( cophthing.icohp[Spin.up][300], chemenvlobster1.get_info_icohps_to_neighbors(isites=[0])[0]) self.assertEqual( chemenvlobster1.get_info_cohps_to_neighbors( path_to_COHPCAR=os.path.join(test_dir_env, "COHPCAR.lobster.mp-190.gz"), isites=[0], only_bonds_to=["Te"], )[0], None, ) self.assertEqual( chemenvlobster1.get_info_cohps_to_neighbors( path_to_COHPCAR=os.path.join(test_dir_env, "COHPCAR.lobster.mp-190.gz"), isites=[0], only_bonds_to=["Te"], )[1], None, ) self.assertEqual( self.chemenvlobster0_NaSi.get_info_cohps_to_neighbors( path_to_COHPCAR=os.path.join(test_dir_env, "COHPCAR.lobster.NaSi.gz"), isites=[8], onlycation_isites=False, only_bonds_to=["Na"], )[0], "1 x Na-Si (per bond)", ) self.assertEqual( self.chemenvlobster0_NaSi.get_info_cohps_to_neighbors( path_to_COHPCAR=os.path.join(test_dir_env, "COHPCAR.lobster.NaSi.gz"), isites=[8], onlycation_isites=False, only_bonds_to=["Si"], )[0], "3 x Si-Si (per bond)", ) chemenvlobster1.plot_cohps_of_neighbors( path_to_COHPCAR=os.path.join(test_dir_env, "COHPCAR.lobster.mp-190.gz"), isites=[0], only_bonds_to=["O"], summed_spin_channels=True, ) chemenvlobster1.plot_cohps_of_neighbors( path_to_COHPCAR=os.path.join(test_dir_env, "COHPCAR.lobster.mp-190.gz"), isites=[0], only_bonds_to=["O"], summed_spin_channels=True, xlim=[-10, 10], ylim=None, ) with self.assertRaises(ValueError): # icohplist and cohpcar do not fit together self.chemenvlobster1.get_info_cohps_to_neighbors( path_to_COHPCAR=os.path.join(test_dir_env, "COHPCAR.lobster.mp-190.gz"), isites=[0], only_bonds_to=None, per_bond=False, ) with self.assertRaises(ValueError): # icohplist and cohpcar do not fit together self.chemenvlobster2.get_info_cohps_to_neighbors( path_to_COHPCAR=os.path.join(test_dir_env, "COHPCAR.lobster.mp-190.gz"), isites=[0], only_bonds_to=None, per_bond=False, )
def setUp(self): # test additional conditions first # only consider cation anion bonds self.chemenvlobster1 = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_190.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_190.gz")), additional_condition=1, ) # all bonds self.chemenvlobster0 = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_190.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_190.gz")), additional_condition=0, ) # only cation cation, anion anion bonds self.chemenvlobster5 = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_190.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_190.gz")), additional_condition=5, ) # only cation cation bonds self.chemenvlobster6 = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_190.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_190.gz")), additional_condition=6, ) # 2,3,4 are not tested so far self.chemenvlobster2 = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_190.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_190.gz")), additional_condition=2, ) self.chemenvlobster3 = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_190.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_190.gz")), additional_condition=3, ) self.chemenvlobster4 = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_190.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_190.gz")), additional_condition=4, ) # search for other testcase where 2,3,4 arrive at different results self.chemenvlobster0_second = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_353.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_353.gz")), additional_condition=0, ) self.chemenvlobster1_second = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_353.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_353.gz")), additional_condition=1, ) self.chemenvlobster2_second = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_353.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_353.gz")), additional_condition=2, ) self.chemenvlobster5_second = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_353.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_353.gz")), additional_condition=5, ) self.chemenvlobster5_second_percentage = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_353.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_353.gz")), additional_condition=5, perc_strength_ICOHP=1.0, ) self.chemenvlobster6_second = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_353.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_353.gz")), additional_condition=6, ) # TODO: use charge instead of valence self.chemenvlobster1_charges = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_353.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_353.gz")), valences_from_charges=True, filename_CHARGE=os.path.join(test_dir_env, "CHARGE.lobster.mp-353.gz"), additional_condition=1, ) self.chemenvlobster1_charges_loewdin = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_353.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_353.gz")), valences_from_charges=True, filename_CHARGE=os.path.join(test_dir_env, "CHARGE.lobster.mp-353.gz"), additional_condition=1, which_charge="Loewdin", ) self.chemenvlobster6_charges_additional_condition = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_353.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_353.gz")), valences_from_charges=True, filename_CHARGE=os.path.join(test_dir_env, "CHARGE.lobster.mp-353.gz"), additional_condition=6, adapt_extremum_to_add_cond=True, ) self.chemenvlobster5_charges_additional_condition = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_353.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_353.gz")), valences_from_charges=True, filename_CHARGE=os.path.join(test_dir_env, "CHARGE.lobster.mp-353.gz"), additional_condition=5, adapt_extremum_to_add_cond=True, ) self.chemenvlobster4_charges_additional_condition = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_353.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_353.gz")), valences_from_charges=True, filename_CHARGE=os.path.join(test_dir_env, "CHARGE.lobster.mp-353.gz"), additional_condition=4, adapt_extremum_to_add_cond=True, ) self.chemenvlobster3_charges_additional_condition = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_353.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_353.gz")), valences_from_charges=True, filename_CHARGE=os.path.join(test_dir_env, "CHARGE.lobster.mp-353.gz"), additional_condition=3, adapt_extremum_to_add_cond=True, ) self.chemenvlobster2_charges_additional_condition = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_353.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_353.gz")), valences_from_charges=True, filename_CHARGE=os.path.join(test_dir_env, "CHARGE.lobster.mp-353.gz"), additional_condition=2, adapt_extremum_to_add_cond=True, ) self.chemenvlobster1_charges_additional_condition = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_353.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_353.gz")), valences_from_charges=True, filename_CHARGE=os.path.join(test_dir_env, "CHARGE.lobster.mp-353.gz"), additional_condition=1, adapt_extremum_to_add_cond=True, ) self.chemenvlobster0_charges_additional_condition = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.mp_353.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.mp_353.gz")), valences_from_charges=True, filename_CHARGE=os.path.join(test_dir_env, "CHARGE.lobster.mp-353.gz"), additional_condition=0, adapt_extremum_to_add_cond=True, ) self.chemenvlobster0_NaSi = LobsterNeighbors( are_coops=False, filename_ICOHP=os.path.join(test_dir_env, "ICOHPLIST.lobster.NaSi.gz"), structure=Structure.from_file( os.path.join(test_dir_env, "POSCAR.NaSi.gz")), valences_from_charges=True, filename_CHARGE=os.path.join(test_dir_env, "CHARGE.lobster.NaSi.gz"), additional_condition=0, adapt_extremum_to_add_cond=True, )