def test_from_multipoles_quad(): c1 = [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0]] q1 = [[1.0], [2.0]] mu1 = [[1.0, 2.0, 3.0], [-1.0, -2.0, -3.0]] theta1 = [[1.0, 2.0, 3.0, 4.0, 5.0, 6.0], [-1.0, 2.0, -3.0, 4.0, -5.0, 6.0]] p1 = Potential.from_multipoles(c1, [q1, mu1, theta1], max_k=2) p1.save("quad_test.pot") p2 = Potential.from_file("tests/quad_test.pot") assert p1 == p2
def test_commutative_addition(): m2p2 = Potential.from_file('tests/m2p2.pot') m0 = Potential.from_file('tests/m0.pot') # check we can add both ways p2 = m0 + m2p2 assert p2.nsites == 15 assert len(p2.polarizabilities) == 15 assert max(p2.multipoles.keys()) == 2 p1 = m2p2 + m0 assert p1.nsites == 15 assert len(p1.polarizabilities) == 15 assert max(p1.multipoles.keys()) == 2
def test_addition(): """ Tests various kinds of potential addition """ # first test addition of empty potentials p0 = Potential() p = p0 + p0 assert p.nsites == 2 * p0.nsites assert p.npols == 2 * p0.npols # do simple potentials and make sure they add both a + b and b + a c1 = [[0.0, 0.0, 0.0]] q1 = [[1.0]] p1 = Potential.from_multipoles(c1, q1) c2 = [[5.4, 0.0, 0.0]] d2 = [[1.0, 1.0, 0.0]] p2 = Potential.from_multipoles(c2, d2) p = p1 + p2 assert p.nsites == p1.nsites + p2.nsites assert p.npols == p1.npols + p2.npols p = p2 + p1 assert p.nsites == p1.nsites + p2.nsites assert p.npols == p1.npols + p2.npols # now add polarizabilities to one p1.polarizabilities = [[1.0, 0.0, 0.0, 1.0, 0.0, 1.0]] assert p1.npols == 1 p = p1 + p2 assert p.nsites == p1.nsites + p2.nsites assert p.npols == p1.npols + p2.npols p = p2 + p1 assert p.nsites == p1.nsites + p2.nsites assert p.npols == p1.npols + p2.npols p2.polarizabilities = [[0.0, 2.0, 2.0, 0.0, 0.0, 2.0]] assert p2.npols == 1 p = p1 + p2 assert p.nsites == p1.nsites + p2.nsites assert p.npols == p1.npols + p2.npols # finally add two potentials with only polarization p3 = Potential.from_file('tests/nomul.pot') print(p3) assert p3.npols == 1 p = p3 + p3 assert p.npols == 2
def test_from_multipoles(): c1 = [[0.0, 0.0, 0.0]] q1 = [[1.0]] p1 = Potential.from_multipoles(c1, q1) assert p1.nsites == 1 assert p1.multipoles[0] == [[1.0]] assert p1.npols == 0 c2 = [[5.4, 0.0, 0.0]] d2 = [[1.0, 1.0, 0.0]] p2 = Potential.from_multipoles(c2, d2) assert p2.nsites == 1 assert p2.multipoles[0] == [[0.0]] assert p2.multipoles[1] == [[1.0, 1.0, 0.0]] assert p2.npols == 0
def make_potentials(self): """ Creates pepytools.Potential objects for every state """ if len(self.multipoles_per_state) != self.n_states: raise Exception( "Invalid number of multipole moments to create potential.", self.n_states, len(self.multipoles_per_state)) self.potentials_per_state = [] for state in range(self.n_states): max_k = self.multipoles_per_state[state].max_k m0 = [list(x) for x in self.multipoles_per_state[state].M0] if max_k == 0: m1 = None m2 = None elif max_k == 1: m1 = [list(x) for x in self.multipoles_per_state[state].M1] m2 = None elif max_k == 2: m1 = [list(x) for x in self.multipoles_per_state[state].M1] m2 = [list(x) for x in self.multipoles_per_state[state].M2] else: m1 = None m2 = None moment_list = [x for x in [m0, m1, m2] if x is not None] # pepytools wants coordinates in AU p = Potential.from_multipoles(1.889725989 * self.coords, moment_list, max_k=max_k) self.potentials_per_state.append(p)
def test_addition_nomul_info(): p1 = Potential() p1.setCoordinates(numpy.asarray([[0.0, 0.0, 0.0]])) p1.setLabels(['He']) p2 = Potential() p2.setCoordinates(numpy.asarray([[1.0, 0.0, 0.0]])) p2.setLabels(['He']) p = p1 + p2
def test_m0_from_file(): p = Potential.from_file('tests/m0.pot') assert p.nsites == 9 # 3 water molecules assert p.npols == 0 print(p)
def test_equality(): p1 = Potential.from_file('tests/m0.pot') p2 = Potential.from_file('tests/m0.pot') print(p1, p2) assert p1 == p2
def test_m2p2_from_file(): p = Potential.from_file('tests/m2p2.pot') assert p.nsites == 6 assert p.npols == 6