def test_orbital_field_matrix(self): ofm_maker = OrbitalFieldMatrix() ofm = ofm_maker.featurize(self.diamond)[0] mtarget = np.zeros((32, 32)) mtarget[1][1] = 1.4789015 # 1.3675444 mtarget[1][3] = 1.4789015 # 1.3675444 mtarget[3][1] = 1.4789015 # 1.3675444 mtarget[3][3] = 1.4789015 # 1.3675444 if for a coord# of exactly 4 for i in range(32): for j in range(32): if not i in [1, 3] and not j in [1, 3]: self.assertEqual(ofm[i, j], 0.0) mtarget = np.matrix(mtarget) self.assertAlmostEqual(np.linalg.norm(ofm - mtarget), 0.0, places=4) ofm_maker = OrbitalFieldMatrix(True) ofm = ofm_maker.featurize(self.diamond)[0] mtarget = np.zeros((39, 39)) mtarget[1][1] = 1.4789015 mtarget[1][3] = 1.4789015 mtarget[3][1] = 1.4789015 mtarget[3][3] = 1.4789015 mtarget[1][33] = 1.4789015 mtarget[3][33] = 1.4789015 mtarget[33][1] = 1.4789015 mtarget[33][3] = 1.4789015 mtarget[33][33] = 1.4789015 mtarget = np.matrix(mtarget) self.assertAlmostEqual(np.linalg.norm(ofm - mtarget), 0.0, places=4)
def test_orbital_field_matrix(self): ofm_maker = OrbitalFieldMatrix() ofm = ofm_maker.featurize(self.diamond)[0] mtarget = np.zeros((32, 32)) mtarget[1][1] = 1.4789015 # 1.3675444 mtarget[1][3] = 1.4789015 # 1.3675444 mtarget[3][1] = 1.4789015 # 1.3675444 mtarget[3][3] = 1.4789015 # 1.3675444 if for a coord# of exactly 4 for i in range(32): for j in range(32): if not i in [1, 3] and not j in [1, 3]: self.assertEqual(ofm[i, j], 0.0) mtarget = np.matrix(mtarget) self.assertAlmostEqual( np.linalg.norm(ofm - mtarget), 0.0, places=4) ofm_maker = OrbitalFieldMatrix(True) ofm = ofm_maker.featurize(self.diamond)[0] mtarget = np.zeros((39, 39)) mtarget[1][1] = 1.4789015 mtarget[1][3] = 1.4789015 mtarget[3][1] = 1.4789015 mtarget[3][3] = 1.4789015 mtarget[1][33] = 1.4789015 mtarget[3][33] = 1.4789015 mtarget[33][1] = 1.4789015 mtarget[33][3] = 1.4789015 mtarget[33][33] = 1.4789015 mtarget = np.matrix(mtarget) self.assertAlmostEqual( np.linalg.norm(ofm - mtarget), 0.0, places=4) ofm_flat = OrbitalFieldMatrix(period_tag=False, flatten=True) self.assertEqual(len(ofm_flat.feature_labels()), 1024) ofm_flat = OrbitalFieldMatrix(period_tag=True, flatten=True) self.assertEqual(len(ofm_flat.feature_labels()), 1521) ofm_vector = ofm_flat.featurize(self.diamond) for ix in [40, 42, 72, 118, 120, 150, 1288, 1320]: self.assertAlmostEqual(ofm_vector[ix], 1.4789015345821415)
def test_orbital_field_matrix(self): ofm_maker = OrbitalFieldMatrix(flatten=False) ofm = ofm_maker.featurize(self.diamond)[0] mtarget = np.zeros((32, 32)) mtarget[1][1] = 1.4789015 # 1.3675444 mtarget[1][3] = 1.4789015 # 1.3675444 mtarget[3][1] = 1.4789015 # 1.3675444 mtarget[3][3] = 1.4789015 # 1.3675444 if for a coord# of exactly 4 for i in range(32): for j in range(32): if not i in [1, 3] and not j in [1, 3]: self.assertEqual(ofm[i, j], 0.0) mtarget = np.matrix(mtarget) self.assertAlmostEqual( np.linalg.norm(ofm - mtarget), 0.0, places=4) ofm_maker = OrbitalFieldMatrix(True, flatten=False) ofm = ofm_maker.featurize(self.diamond)[0] mtarget = np.zeros((39, 39)) mtarget[1][1] = 1.4789015 mtarget[1][3] = 1.4789015 mtarget[3][1] = 1.4789015 mtarget[3][3] = 1.4789015 mtarget[1][33] = 1.4789015 mtarget[3][33] = 1.4789015 mtarget[33][1] = 1.4789015 mtarget[33][3] = 1.4789015 mtarget[33][33] = 1.4789015 mtarget = np.matrix(mtarget) self.assertAlmostEqual( np.linalg.norm(ofm - mtarget), 0.0, places=4) ofm_flat = OrbitalFieldMatrix(period_tag=False, flatten=True) self.assertEqual(len(ofm_flat.feature_labels()), 1024) ofm_flat = OrbitalFieldMatrix(period_tag=True, flatten=True) self.assertEqual(len(ofm_flat.feature_labels()), 1521) ofm_vector = ofm_flat.featurize(self.diamond) for ix in [40, 42, 72, 118, 120, 150, 1288, 1320]: self.assertAlmostEqual(ofm_vector[ix], 1.4789015345821415)
import numpy as np from matminer.featurizers.structure import OrbitalFieldMatrix cen_structures = np.load( '/home/dennis/Dropbox/mp_share_dt_ag/structs/centrosymmetric_insulators.npy', allow_pickle=True) print(len(cen_structures)) #create ofm representations ofm = OrbitalFieldMatrix() cen_ofm = [] for item in cen_structures: cen_ofm.append(ofm.featurize(item)) np.save('centrosymmetric_ofm_representation.npy', cen_ofm) non_cen_structures = np.load( '/home/dennis/Dropbox/mp_share_dt_ag/structs/non_centrosymmetric_insulators.npy', allow_pickle=True) print(len(non_cen_structures)) non_cen_ofm = [] for item in non_cen_structures: non_cen_ofm.append(ofm.featurize(item)) np.save('non_centrosymmetric_ofm_representation.npy', non_cen_ofm)