def setUp(self): data = get_data_from_file_fchk('pirrol.in.fchk') self.pirrol = WfnSympy( coordinates=data['coordinates'], symbols=data['symbols'], basis=data['basis'], center=[0., 0., 0.], axis=[1., 0., 0.], # axis2=[0., 0., 1.], alpha_mo_coeff=data['mo_coefficients']['alpha'][:18], alpha_occupancy=data['alpha_occupancy'], beta_occupancy=data['beta_occupancy'], group='C6v')
def setUp(self): self.data = get_data_from_file_fchk('ammonia.fchk') self.structure = WfnSympy( coordinates=self.data['coordinates'], symbols=self.data['symbols'], basis=self.data['basis'], axis=[0.55944897, 0.69527034, -0.4512383], axis2=[0., -0.4512383, -0.69527034], alpha_mo_coeff=self.data['mo_coefficients']['alpha'], group='C3v')
def get_wf_symmetry(structure, basis, mo_coeff, center=None, orientation=(0., 0., 1.), orientation2=(0, 1, 0), group='C2h', occupancy=None): """ Simplified interface between pyqchem anf wfnsympy :param structure: molecular geometry (3xn) array :param basis: dictionary containing the basis :param mo_coeff: molecular orbitals coefficients :param center: center of the molecule :param orientation: unit vector perpendicular to the plane of the molecule :param group: point symmetry group :return molsym: wfnsympy object """ alpha_mo_coeff = np.array(mo_coeff['alpha']).tolist() alpha_occupancy = [0] * len(mo_coeff['alpha']) alpha_occupancy[:int(structure.alpha_electrons )] = [1] * structure.alpha_electrons if 'beta' in mo_coeff: beta_mo_coeff = np.array(mo_coeff['beta']).tolist() beta_occupancy = [0] * len(mo_coeff['beta']) beta_occupancy[:int(structure.alpha_electrons )] = [1] * structure.alpha_electrons else: beta_mo_coeff = None beta_occupancy = None if occupancy is not None: alpha_occupancy = occupancy['alpha'] if 'beta' in occupancy: beta_occupancy = occupancy['beta'] molsym = WfnSympy( coordinates=structure.get_coordinates(), symbols=structure.get_symbols(), basis=basis, center=center, axis=orientation, axis2=orientation2, alpha_mo_coeff=alpha_mo_coeff, beta_mo_coeff=beta_mo_coeff, alpha_occupancy=alpha_occupancy, beta_occupancy=beta_occupancy, #charge=structure.charge, #multiplicity=structure.multiplicity, group=group) return molsym
def test_dens_occupancy(self): self.structure = WfnSympy( coordinates=self.data['coordinates'], symbols=self.data['symbols'], basis=self.data['basis'], axis=[0.55944897, 0.69527034, -0.4512383], axis2=[0., -0.4512383, -0.69527034], alpha_mo_coeff=self.data['mo_coefficients']['alpha'], group='C3v', alpha_occupancy=[0, 1, 1, 1, 1]) np.testing.assert_allclose(4.5067, self.structure.csm_dens, rtol=1e-03)
def test_precision(self): self.structure = WfnSympy( coordinates=self.data['coordinates'], symbols=self.data['symbols'], basis=self.data['basis'], axis=[0.55944897, 0.69527034, -0.4512383], axis2=[0., -0.4512383, -0.69527034], alpha_mo_coeff=self.data['mo_coefficients']['alpha'], group='C3v', tolerance=1e-04, alpha_occupancy=self.data['alpha_occupancy'], beta_occupancy=self.data['beta_occupancy']) np.testing.assert_allclose(0.148, self.structure.csm_dens, rtol=1e-03)
def target_function(alpha, beta): ax1 = np.dot(rotation_xy(alpha, beta), [1, 0, 0]) # ax2 = np.dot(rotation_xy(alpha, beta), [0, 0, 1]) pirrol = WfnSympy( coordinates=data['coordinates'], symbols=data['symbols'], basis=data['basis'], center=c_geom, axis=ax1, # axis2=ax2, alpha_mo_coeff=data['mo_coefficients']['alpha'], group='C5') res = np.sum(np.sqrt(pirrol.csm_coef)) return res
def _get_wfnsym_results(self, group): if self._electronic_structure is None: raise Exception('Electronic structure not set') key = _get_key_wfnsym(group, self._axis, self._axis2, self._center, self._electronic_structure.alpha_occupancy, self._electronic_structure.beta_occupancy) if key not in self._results: self._results[key] = WfnSympy( coordinates=self._coordinates, symbols=self._symbols, basis=self._electronic_structure.basis, center=self._center, axis=self._axis, axis2=self._axis2, alpha_mo_coeff=self._electronic_structure.coefficients_a, beta_mo_coeff=self._electronic_structure.coefficients_b, group=group.upper(), alpha_occupancy=self._electronic_structure.alpha_occupancy, beta_occupancy=self._electronic_structure.beta_occupancy) return self._results[key]
def test_degenerate_3(self): configurations = [ [[1, 1, 1, 1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 1, 0, 1, 0, 0]], [[1, 1, 1, 1, 1, 1, 0, 0, 0], [1, 1, 1, 1, 1, 0, 0, 1, 0]], [[1, 1, 1, 1, 1, 0, 1, 0, 0], [1, 1, 1, 1, 1, 1, 0, 0, 0]], [[1, 1, 1, 1, 1, 0, 1, 0, 0], [1, 1, 1, 1, 1, 0, 0, 1, 0]], [[1, 1, 1, 1, 1, 0, 0, 1, 0], [1, 1, 1, 1, 1, 1, 0, 0, 0]], [[1, 1, 1, 1, 1, 0, 0, 1, 0], [1, 1, 1, 1, 1, 0, 1, 0, 0]], ] for conf_alpha, conf_beta in configurations: print(conf_alpha, conf_beta) wf_results = WfnSympy( coordinates=self.data['coordinates'], symbols=self.data['symbols'], basis=self.data['basis'], axis=[ -0.5634811520306573, 0.5937396995245904, -0.5744233286650642 ], axis2=[ -0.5910397590456458, -0.5756503475754583, 0.5650652002764983 ], alpha_mo_coeff=self.data['mo_coefficients']['alpha'], group='Td', alpha_occupancy=conf_alpha, beta_occupancy=conf_beta, ) wf_results.print_alpha_mo_IRD() wf_results.print_wf_mo_IRD() wf_alpha = np.round(wf_results.wf_IRd_a, decimals=2) wf_beta = np.round(wf_results.wf_IRd_b, decimals=2) wf_total = np.round(wf_results.wf_IRd, decimals=2) print(wf_alpha, wf_beta, wf_total) self.assertTupleEqual(tuple(wf_alpha), (0., 0., 0., 1., 0.)) self.assertTupleEqual(tuple(wf_beta), (0., 0., 0., 1., 0.)) self.assertTupleEqual(tuple(wf_total), (0., 0., 0., 0.5, 0.5))
def get_wf_symmetry(structure, basis, mo_coeff, center=None, orientation=(0., 0., 1.), orientation2=(0, 1, 0), group='C2h'): """ Simplified interface between pyqchem anf wfnsympy :param structure: molecular geometry (3xn) array :param basis: dictionary containing the basis :param mo_coeff: molecular orbitals coefficients :param center: center of the molecule :param orientation: unit vector perpendicular to the plane of the molecule :param group: point symmetry group :return molsym: wfnsympy object """ alpha_mo_coeff = np.array(mo_coeff['alpha']).tolist() if 'beta' in mo_coeff: beta_mo_coeff = np.array(mo_coeff['beta']).tolist() else: beta_mo_coeff = None molsym = WfnSympy(coordinates=structure.get_coordinates(), symbols=structure.get_symbols(), basis=basis, center=center, VAxis=orientation, VAxis2=orientation2, alpha_mo_coeff=alpha_mo_coeff, beta_mo_coeff=beta_mo_coeff, charge=structure.charge, multiplicity=structure.multiplicity, group=group) return molsym
class TestWfnsympy(unittest.TestCase): def setUp(self): data = get_data_from_file_fchk('pirrol.in.fchk') self.pirrol = WfnSympy( coordinates=data['coordinates'], symbols=data['symbols'], basis=data['basis'], center=[0., 0., 0.], axis=[1., 0., 0.], # axis2=[0., 0., 1.], alpha_mo_coeff=data['mo_coefficients']['alpha'][:18], alpha_occupancy=data['alpha_occupancy'], beta_occupancy=data['beta_occupancy'], group='C6v') def test_symlab(self): symlab_test = [ 'E', '2C6', '2C3', 'C2', 's_v1', 's_d1', 's_v2', 's_d2', 's_v3', 's_d3' ] self.assertEqual(self.pirrol.SymLab, symlab_test) def test_csm_coef(self): csm_coef_test = [ 5.331142e-07, 9.999894e+01, 1.000000e+02, 1.000000e+02, 1.000000e+02, 1.000000e+02, 9.999894e+01, 5.331136e-07, 9.999894e+01, 1.000000e+02 ] np.testing.assert_allclose(csm_coef_test, self.pirrol.csm_coef, rtol=1e-6) def test_mo_SOEVs_a(self): mo_soevs_a_test = [ [ 1.00000000e+00, -1.32522730e-03, -2.85032614e-05, 3.06252669e-05, 3.06252669e-05, -2.85032614e-05, -1.32522730e-03, 1.00000000e+00, -1.32522730e-03, -2.85032614e-05 ], [ 1.00000000e+00, 1.58035432e-03, -3.10152695e-02, -2.47373332e-02, 2.47373332e-02, 3.10152695e-02, -1.58035432e-03, -1.00000000e+00, -1.58035432e-03, 3.10152695e-02 ], [ 1.00000000e+00, 8.01242421e-04, 3.03781569e-02, 2.42405846e-02, 2.42405846e-02, 3.03781569e-02, 8.01242421e-04, 1.00000000e+00, 8.01242421e-04, 3.03781569e-02 ], [ 1.00000000e+00, 2.18367913e-01, 3.02127679e-04, -1.91732435e-04, -1.91732435e-04, 3.02127680e-04, 2.18367913e-01, 1.00000000e+00, 2.18367913e-01, 3.02127679e-04 ], [ 1.00000000e+00, -2.24480923e-01, -1.21956191e-04, 9.67591395e-06, -9.67591395e-06, 1.21956191e-04, 2.24480923e-01, -1.00000000e+00, 2.24480923e-01, 1.21956191e-04 ], [ 1.00000000e+00, 7.97590267e-01, 6.16140384e-01, 5.62311755e-01, 5.62311755e-01, 6.16140384e-01, 7.97590267e-01, 1.00000000e+00, 7.97590267e-01, 6.16140384e-01 ], [ 1.00000000e+00, 5.06929014e-01, -1.34275096e-01, -3.75219254e-01, -3.75219254e-01, -1.34275096e-01, 5.06929014e-01, 1.00000000e+00, 5.06929014e-01, -1.34275096e-01 ], [ 1.00000000e+00, 4.09168542e-01, -4.50809663e-01, -8.28810626e-01, 8.28810626e-01, 4.50809663e-01, -4.09168542e-01, -1.00000000e+00, -4.09168542e-01, 4.50809663e-01 ], [ 9.99999998e-01, -1.45640081e-01, -7.07265257e-02, 4.98181993e-01, 4.98181993e-01, -7.07265257e-02, -1.45640081e-01, 9.99999998e-01, -1.45640081e-01, -7.07265257e-02 ], [ 1.00000000e+00, -5.14408504e-01, -3.22442719e-01, 6.92978124e-01, -6.92978124e-01, 3.22442719e-01, 5.14408504e-01, -1.00000000e+00, 5.14408504e-01, 3.22442719e-01 ], [ 9.99999998e-01, 5.68141874e-01, 4.92191987e-01, 6.78888006e-01, 6.78888006e-01, 4.92191987e-01, 5.68141874e-01, 9.99999998e-01, 5.68141874e-01, 4.92191987e-01 ], [ 1.00000000e+00, 1.44894779e-01, -2.23530452e-01, -3.63772946e-01, -3.63772946e-01, -2.23530452e-01, 1.44894779e-01, 1.00000000e+00, 1.44894779e-01, -2.23530452e-01 ], [ 9.99999999e-01, -2.09577512e-01, -5.34982970e-02, -3.85232598e-01, 3.85232598e-01, 5.34982970e-02, 2.09577512e-01, -9.99999999e-01, 2.09577512e-01, 5.34982970e-02 ], [ 9.99999999e-01, 8.94091923e-01, 7.88572690e-01, 7.46740593e-01, 7.46740593e-01, 7.88572690e-01, 8.94091923e-01, 9.99999999e-01, 8.94091923e-01, 7.88572690e-01 ], [ 1.00000000e+00, -3.43439533e-01, 6.92332621e-02, -3.67952436e-01, 3.67952436e-01, -6.92332621e-02, 3.43439533e-01, -1.00000000e+00, 3.43439533e-01, -6.92332621e-02 ], [ 9.99999998e-01, -6.52313367e-01, 3.71284414e-01, -3.90435661e-01, -3.90435661e-01, 3.71284414e-01, -6.52313367e-01, 9.99999998e-01, -6.52313367e-01, 3.71284414e-01 ], [ 9.99999999e-01, 4.40770928e-01, -3.00193848e-01, -5.75538171e-01, -5.75538171e-01, -3.00193848e-01, 4.40770928e-01, 9.99999999e-01, 4.40770928e-01, -3.00193848e-01 ], [ 1.00000000e+00, 4.37251180e-01, -4.82843548e-01, -8.48062831e-01, 8.48062831e-01, 4.82843548e-01, -4.37251180e-01, -1.00000000e+00, -4.37251180e-01, 4.82843548e-01 ] ] self.pirrol.print_overlap_mo_alpha() np.testing.assert_allclose(mo_soevs_a_test, self.pirrol.mo_SOEVs_a, rtol=1e-6) def test_wf_SOEVs_a(self): wf_soevs_a_test = [ 9.99999997e-01, 3.25103201e-03, 8.71324571e-08, -2.99110905e-08, 2.99110905e-08, -8.71324571e-08, -3.25103201e-03, -9.99999997e-01, -3.25103201e-03, -8.71324571e-08 ] np.testing.assert_allclose(wf_soevs_a_test, self.pirrol.wf_SOEVs_a, rtol=1e-6) def test_grim_coef(self): grim_coef_test = [ 1.480872e-08, 6.382904e+01, 7.534673e+01, 5.909258e+01, 5.909258e+01, 7.534673e+01, 6.382904e+01, 1.480871e-08, 6.382904e+01, 7.534673e+01 ] np.testing.assert_allclose(grim_coef_test, self.pirrol.grim_coef, rtol=1e-6)
0.000000000, 0.000000000, 0.000000000 ], [ -0.125818566, 0.820120983, 0.000000000, 0.000000000, -0.763538862, -0.769155124, -0.769155124 ], [ 0.000000000, 0.000000000, 0.959800163, 0.000000000, 0.000000000, 0.814629717, -0.814629717 ]] wf_results = WfnSympy( coordinates=[[0.0000000000, 0.0000000000, -0.0428008531], [-0.7581074140, 0.0000000000, -0.6785995734], [0.7581074140, 0.000000000, -0.6785995734]], symbols=['O', 'H', 'H'], basis=basis, alpha_mo_coeff=mo_coefficients[:5], alpha_occupancy=[0, 1, 1, 0, 0], beta_occupancy=[1, 1, 1, 1, 1], group='c2v') wf_results.print_alpha_mo_IRD() wf_results.print_overlap_mo_alpha() wf_results.print_overlap_wf() wf_results.print_wf_mo_IRD() def get_orbital_state(orbital_soev): state_orb = SymmetryBase(group='c2v', rep=pd.Series(orbital_soev, index=["E", "C2", "sv_xz",
from wfnsympy import WfnSympy from wfnsympy.file_io import get_data_from_file_fchk import numpy as np # data = get_data_from_file_fchk('pirrol.in.fchk') data = get_data_from_file_fchk('methane.fchk') structure = WfnSympy( coordinates=data['coordinates'], symbols=data['symbols'], basis=data['basis'], alpha_mo_coeff=data['mo_coefficients']['alpha'], # center=[0., 0., 0.], # axis=[0., 0., 1.], # axis2=[0, 1, 0], alpha_occupancy=data['alpha_occupancy'], beta_occupancy=data['beta_occupancy'], group='Td') structure.print_CSM() structure.print_overlap_mo_alpha() structure.print_dens_CSM() print('axis: ', structure.axis, np.linalg.norm(structure.axis)) print('axis2: ', structure.axis2, np.linalg.norm(structure.axis2)) print('center: ', structure.center)
def setUp(self): basis = { 'name': 'STO-3G', 'primitive_type': 'gaussian', 'atoms': [{ 'symbol': 'O', 'shells': [{ 'shell_type': 's', 'p_exponents': [130.70932, 23.808861, 6.4436083], 'con_coefficients': [0.154328969, 0.535328136, 0.444634536], 'p_con_coefficients': [0.0, 0.0, 0.0] }, { 'shell_type': 'sp', 'p_exponents': [5.0331513, 1.1695961, 0.380389], 'con_coefficients': [-0.0999672287, 0.399512825, 0.700115461], 'p_con_coefficients': [0.155916268, 0.607683714, 0.391957386] }] }, { 'symbol': 'H', 'shells': [{ 'shell_type': 's', 'p_exponents': [3.42525091, 0.62391373, 0.1688554], 'con_coefficients': [0.154328971, 0.535328142, 0.444634542], 'p_con_coefficients': [0.0, 0.0, 0.0] }] }, { 'symbol': 'H', 'shells': [{ 'shell_type': 's', 'p_exponents': [3.42525091, 0.62391373, 0.1688554], 'con_coefficients': [0.154328971, 0.535328142, 0.444634542], 'p_con_coefficients': [0.0, 0.0, 0.0] }] }] } mo_coefficients = [[ 0.994216442, 0.025846814, 0.000000000, 0.000000000, -0.004164076, -0.005583712, -0.005583712 ], [ 0.233766661, -0.844456594, 0.000000000, 0.000000000, 0.122829781, -0.155593214, -0.155593214 ], [ 0.000000000, 0.000000000, 0.612692349, 0.000000000, 0.000000000, -0.449221684, 0.449221684 ], [ -0.104033343, 0.538153649, 0.000000000, 0.000000000, 0.755880259, -0.295107107, -0.295107107 ], [ 0.000000000, 0.000000000, 0.000000000, -1.000000000, 0.000000000, 0.000000000, 0.000000000 ], [ -0.125818566, 0.820120983, 0.000000000, 0.000000000, -0.763538862, -0.769155124, -0.769155124 ], [ 0.000000000, 0.000000000, 0.959800163, 0.000000000, 0.000000000, 0.814629717, -0.814629717 ]] self.wf_results = WfnSympy( coordinates=[[0.0000000000, 0.0000000000, -0.0428008531], [-0.7581074140, 0.0000000000, -0.6785995734], [0.7581074140, 0.000000000, -0.6785995734]], symbols=['O', 'H', 'H'], basis=basis, alpha_mo_coeff=mo_coefficients[:5], group='C2v') self.wf_results.print_alpha_mo_IRD()
class TestWfnsympy(unittest.TestCase): def setUp(self): basis = { 'name': 'STO-3G', 'primitive_type': 'gaussian', 'atoms': [{ 'symbol': 'O', 'shells': [{ 'shell_type': 's', 'p_exponents': [130.70932, 23.808861, 6.4436083], 'con_coefficients': [0.154328969, 0.535328136, 0.444634536], 'p_con_coefficients': [0.0, 0.0, 0.0] }, { 'shell_type': 'sp', 'p_exponents': [5.0331513, 1.1695961, 0.380389], 'con_coefficients': [-0.0999672287, 0.399512825, 0.700115461], 'p_con_coefficients': [0.155916268, 0.607683714, 0.391957386] }] }, { 'symbol': 'H', 'shells': [{ 'shell_type': 's', 'p_exponents': [3.42525091, 0.62391373, 0.1688554], 'con_coefficients': [0.154328971, 0.535328142, 0.444634542], 'p_con_coefficients': [0.0, 0.0, 0.0] }] }, { 'symbol': 'H', 'shells': [{ 'shell_type': 's', 'p_exponents': [3.42525091, 0.62391373, 0.1688554], 'con_coefficients': [0.154328971, 0.535328142, 0.444634542], 'p_con_coefficients': [0.0, 0.0, 0.0] }] }] } mo_coefficients = [[ 0.994216442, 0.025846814, 0.000000000, 0.000000000, -0.004164076, -0.005583712, -0.005583712 ], [ 0.233766661, -0.844456594, 0.000000000, 0.000000000, 0.122829781, -0.155593214, -0.155593214 ], [ 0.000000000, 0.000000000, 0.612692349, 0.000000000, 0.000000000, -0.449221684, 0.449221684 ], [ -0.104033343, 0.538153649, 0.000000000, 0.000000000, 0.755880259, -0.295107107, -0.295107107 ], [ 0.000000000, 0.000000000, 0.000000000, -1.000000000, 0.000000000, 0.000000000, 0.000000000 ], [ -0.125818566, 0.820120983, 0.000000000, 0.000000000, -0.763538862, -0.769155124, -0.769155124 ], [ 0.000000000, 0.000000000, 0.959800163, 0.000000000, 0.000000000, 0.814629717, -0.814629717 ]] self.wf_results = WfnSympy( coordinates=[[0.0000000000, 0.0000000000, -0.0428008531], [-0.7581074140, 0.0000000000, -0.6785995734], [0.7581074140, 0.000000000, -0.6785995734]], symbols=['O', 'H', 'H'], basis=basis, alpha_mo_coeff=mo_coefficients[:5], group='C2v') self.wf_results.print_alpha_mo_IRD() def test_csm_coef(self): csm_coef_test = [0, 0, 0, 0] np.testing.assert_allclose(csm_coef_test, self.wf_results.csm_coef, atol=1e-5) def test_mo_SOEVs_a(self): mo_soevs_a_test = [[1, 1, 1, 1], [1, 1, 1, 1], [1, -1, 1, -1], [1, 1, 1, 1], [1, -1, -1, 1]] self.wf_results.print_overlap_mo_alpha() np.testing.assert_allclose(mo_soevs_a_test, self.wf_results.mo_SOEVs_a, atol=1e-5) def test_wf_SOEVs_a(self): wf_soevs_a_test = [1, 1, -1, -1] np.testing.assert_allclose(wf_soevs_a_test, self.wf_results.wf_SOEVs_a, atol=1e-5) def test_grim_coef(self): grim_coef_test = [0, 0, 0, 0] np.testing.assert_allclose(grim_coef_test, self.wf_results.grim_coef, atol=1e-5)