Example #1
0
 def test_forces_random_structure(self):
     atoms = FaceCenteredCubic('H', size=[2,2,2], latticeconstant=2.37126)
     calc = Polydisperse(InversePowerLawPotential(1.0, 1.4, 0.1, 3, 1, 2.22))
     atoms.set_masses(masses=np.repeat(1.0, len(atoms)))       
     atoms.set_array("size", np.random.uniform(1.0, 2.22, size=len(atoms)), dtype=float)
     atoms.set_calculator(calc)
     f = atoms.get_forces()
     fn = calc.calculate_numerical_forces(atoms, d=0.0001)
     self.assertArrayAlmostEqual(f, fn, tol=self.tol)
Example #2
0
    def test_symmetry_sparse(self):
        """
        Test the symmetry of the dense Hessian matrix 

        """
        atoms = FaceCenteredCubic('H', size=[2,2,2], latticeconstant=2.37126)
        calc = Polydisperse(InversePowerLawPotential(1.0, 1.4, 0.1, 3, 1, 2.22))
        atoms.set_masses(masses=np.repeat(1.0, len(atoms)))       
        atoms.set_array("size", np.random.uniform(1.0, 2.22, size=len(atoms)), dtype=float)
        atoms.set_calculator(calc)
        dyn = FIRE(atoms)
        dyn.run(fmax=1e-5)
        H = calc.hessian_matrix(atoms)
        H = H.todense()
        self.assertArrayAlmostEqual(np.sum(np.abs(H-H.T)), 0, tol=1e-5)
Example #3
0
 def test_hessian_random_structure(self):
     """
     Test the computation of the Hessian matrix 
     """
     atoms = FaceCenteredCubic('H', size=[2,2,2], latticeconstant=2.37126)
     calc = Polydisperse(InversePowerLawPotential(1.0, 1.4, 0.1, 3, 1, 2.22))
     atoms.set_masses(masses=np.repeat(1.0, len(atoms)))       
     atoms.set_array("size", np.random.uniform(1.0, 2.22, size=len(atoms)), dtype=float)
     atoms.set_calculator(calc)
     dyn = FIRE(atoms)
     dyn.run(fmax=1e-5)
     H_analytical = calc.hessian_matrix(atoms)
     H_analytical = H_analytical.todense()
     H_numerical = fd_hessian(atoms, dx=1e-5, indices=None)
     H_numerical = H_numerical.todense()
     self.assertArrayAlmostEqual(H_analytical, H_numerical, tol=self.tol)
Example #4
0
 def test_hessian_divide_by_masses(self):
     """
     Test the computation of the Hessian matrix 
     """
     atoms = FaceCenteredCubic('H', size=[2,2,2], latticeconstant=2.37126)     
     atoms.set_array("size", np.random.uniform(1.0, 2.22, size=len(atoms)), dtype=float)
     masses_n = np.random.randint(1, 10, size=len(atoms))
     atoms.set_masses(masses=masses_n)
     calc = Polydisperse(InversePowerLawPotential(1.0, 1.4, 0.1, 3, 1, 2.22))
     atoms.set_calculator(calc)
     dyn = FIRE(atoms)
     dyn.run(fmax=1e-5)
     D_analytical = calc.hessian_matrix(atoms, divide_by_masses=True)
     D_analytical = D_analytical.todense()
     H_analytical = calc.hessian_matrix(atoms)
     H_analytical = H_analytical.todense()
     masses_nc = masses_n.repeat(3)
     H_analytical /= np.sqrt(masses_nc.reshape(-1,1)*masses_nc.reshape(1,-1))
     self.assertArrayAlmostEqual(H_analytical, D_analytical, tol=self.tol)