Ejemplo n.º 1
0
 def test_printed_potential_match(self):
     p = Potential.from_file('m2p2.pot')
     with open('printed_potential.pot', 'w') as f:
         f.write(str(p))
     p2 = Potential.from_file('printed_potential.pot')
     self.assertEqual(p == p2, True)
     delete_file('printed_potential.pot')
Ejemplo n.º 2
0
    def test_potential_charge(self):
        """ tests the total charge """
        p = Potential.from_file('m0.pot')
        self.assertEqual(p.charge, 0)

        p = Potential.from_file('nomul.pot')
        self.assertEqual(p.charge, 0)
Ejemplo n.º 3
0
    def test_potential_charge(self):
        """ tests the total charge """
        p = Potential.from_file('m0.pot')
        self.assertEqual(p.charge, 0)

        p = Potential.from_file('nomul.pot')
        self.assertEqual(p.charge, 0)
Ejemplo n.º 4
0
 def test_printed_potential_match(self):
     p = Potential.from_file('m2p2.pot')
     with open('printed_potential.pot', 'w') as f:
         f.write(str(p))
     p2 = Potential.from_file('printed_potential.pot')
     self.assertEqual(p == p2, True)
     delete_file('printed_potential.pot')
Ejemplo n.º 5
0
    def test_add_potentials_with_multipoles_mixed(self):
        """ Adds potentials with mixed multipole moments """
        m2p2 = Potential.from_file('m2p2.pot')
        m0 = Potential.from_file('m0.pot')

        # check we can add both ways
        p2 = m0 + m2p2
        self.assertEqual(p2.nsites, 15)
        self.assertEqual(len(p2.polarizabilities), 15)
        self.assertEqual(max(p2.multipoles.keys()), 2)

        p1 = m2p2 + m0
        self.assertEqual(p1.nsites, 15)
        self.assertEqual(len(p1.polarizabilities), 15)
        self.assertEqual(max(p1.multipoles.keys()), 2)
Ejemplo n.º 6
0
    def test_add_potentials_with_multipoles_mixed(self):
        """ Adds potentials with mixed multipole moments """
        m2p2 = Potential.from_file('m2p2.pot')
        m0 = Potential.from_file('m0.pot')

        # check we can add both ways
        p2 = m0 + m2p2
        self.assertEqual(p2.nsites, 15)
        self.assertEqual(len(p2.polarizabilities), 15)
        self.assertEqual(max(p2.multipoles.keys()), 2)

        p1 = m2p2 + m0
        self.assertEqual(p1.nsites, 15)
        self.assertEqual(len(p1.polarizabilities), 15)
        self.assertEqual(max(p1.multipoles.keys()), 2)
Ejemplo n.º 7
0
 def test_get_pol_matrix(self):
     """ polarization matrix """
     p = Potential.from_file('nomul.pot')
     pol = p.polarizabilities[0]
     mat = util.get_polarization_matrix(p)
     self.assertEqual(pol[0], mat[0,0])
     self.assertEqual(pol[3], mat[1,1])
     self.assertEqual(pol[5], mat[2,2])
Ejemplo n.º 8
0
    def setUp(self):
        c1 = [[0.0, 0.0, 0.0]]
        q1 = [[1.0]]
        self.p1 = Potential.from_multipoles( c1, q1 )
        c2 = [[5.4, 0.0, 0.0]]
        d2 = [[1.0, 1.0, 0.0]]
        self.p2 = Potential.from_multipoles( c2, d2 )

        # a potential from a file
        self.pfile = Potential.from_file('pehf_iter.pot')
Ejemplo n.º 9
0
    def setUp(self):
        c1 = [[0.0, 0.0, 0.0]]
        q1 = [[1.0]]
        self.p1 = Potential.from_multipoles(c1, q1)
        c2 = [[5.4, 0.0, 0.0]]
        d2 = [[1.0, 1.0, 0.0]]
        self.p2 = Potential.from_multipoles(c2, d2)

        # a potential from a file
        self.pfile = Potential.from_file('pehf_iter.pot')
Ejemplo n.º 10
0
 def test_add_potentials_with_only_polarization(self):
     """ Potential addition with only polarization """
     p = Potential.from_file('nomul.pot')
     p2 = p + p
     self.assertEqual(p2.nsites, 2)
     self.assertEqual(p2.npols, 2)
Ejemplo n.º 11
0
 def test_nopol_potential_fails(self):
     """ testing that potential without polarizibility correctly loads """
     p = Potential.from_file('nopol.pot')
     self.assertEqual(p.nsites, 3)
     self.assertEqual(p.npols, 0)
Ejemplo n.º 12
0
 def test_potential_equal(self):
     """ tests equality of potentials """
     p = Potential.from_file('m0.pot')
     self.assertEqual(p == p, True)
Ejemplo n.º 13
0
 def test_add_potentials_with_only_polarization(self):
     """ Potential addition with only polarization """
     p = Potential.from_file('nomul.pot')
     p2 = p + p
     self.assertEqual(p2.nsites, 2)
     self.assertEqual(p2.npols, 2)
Ejemplo n.º 14
0
 def test_potential_equal(self):
     """ tests equality of potentials """
     p = Potential.from_file('m0.pot')
     self.assertEqual(p == p, True)
Ejemplo n.º 15
0
 def test_nopol_potential_fails(self):
     """ testing that potential without polarizibility correctly loads """
     p = Potential.from_file('nopol.pot')
     self.assertEqual(p.nsites, 3)
     self.assertEqual(p.npols, 0)
Ejemplo n.º 16
0
            # linear combination of all the stored guesses so far
            new_guess = numpy.zeros(numpy.shape(self.guess_storage[0]))
            for i in range(n):
                new_guess += coeff[i] * self.guess_storage[i]

            # remove unwanted (non-contributing) solutions from the
            # DIIS space
            selection = list(numpy.where(numpy.abs(coeff) < self.diis_vector_threshold)[0])
            selection.reverse()
            for i in selection:
                self.guess_storage.pop(i)
                self.diff_storage.pop(i)

        return new_guess

if __name__ == '__main__':
    import sys

    from fields import get_static_field
    from potential import Potential
    from util import get_interaction_matrix, get_polarization_matrix

    filename = sys.argv[1]
    p = Potential.from_file(filename)

    polmat = get_polarization_matrix(p)
    intmat = get_interaction_matrix(p, induced_damping=True)
    field = get_static_field(p)
    s = IterativeDIISSolver(polmat, intmat, field, verbose = True, threshold = 1.0e-5)
    result = s.Solve()
Ejemplo n.º 17
0
            # DIIS space
            selection = list(
                numpy.where(numpy.abs(coeff) < self.diis_vector_threshold)[0])
            selection.reverse()
            for i in selection:
                self.guess_storage.pop(i)
                self.diff_storage.pop(i)

        return new_guess


if __name__ == '__main__':
    import sys

    from fields import get_static_field
    from potential import Potential
    from util import get_interaction_matrix, get_polarization_matrix

    filename = sys.argv[1]
    p = Potential.from_file(filename)

    polmat = get_polarization_matrix(p)
    intmat = get_interaction_matrix(p, induced_damping=True)
    field = get_static_field(p)
    s = IterativeDIISSolver(polmat,
                            intmat,
                            field,
                            verbose=True,
                            threshold=1.0e-5)
    result = s.Solve()