コード例 #1
0
ファイル: Quantities.py プロジェクト: AKrishnachand/n2dm
    def calc_impurity_energy(self, structure, elements):
        if structure not in ['oct38-center', 'oct38-face', 'oct38-edge']:
            raise ValueError("Cannot calculate impurity energy for '%s'" %
                             (structure, ))

        if len(elements) != 2:
            raise ValueError("Tuple of elements must be of length two")

        if self.debug:
            print "Calculating impurity energy..."
            print 40 * "*"
            print "Structure: %s" % (structure, )
            print "Elements: %s\n" % (elements, )

        name, impurity = structure.split('-')
        sym = reference_states[atomic_numbers[elements[1]]]['symmetry']
        latticeconstant = self.get_lattice_constant_a(sym, (elements[1], ))

        if name == 'oct38':
            sites = {'center': 10, 'face': 9, 'edge': 0}

            atoms = Octahedron(elements[1], 4, 1, latticeconstant)
            atoms.set_calculator(self.get_calc())

            dyn = BFGS(atoms, logfile=None, trajectory=None)
            dyn.run(fmax=0.001, steps=100)
            assert dyn.converged()
            s_clean = dyn.get_number_of_steps()
            e_clean = atoms.get_potential_energy()

            atoms[sites[impurity]].symbol = elements[0]

            dyn.run(fmax=0.001, steps=100)
            assert dyn.converged()
            s_impurity = dyn.get_number_of_steps()
            e_impurity = atoms.get_potential_energy()

        self.values[('impurity_energy', structure,
                     elements)] = e_impurity - e_clean

        if self.debug:
            print "BFGS steps: %i    %i" % (s_clean, s_impurity)
            print "Impurity energy: %.5f - %.5f = %.5f eV" % (
                e_impurity, e_clean, e_impurity - e_clean)
            print 40 * "-" + "\n"
コード例 #2
0
def test_fake_ase_opt():
    atoms = Icosahedron("Ar", noshells=2, latticeconstant=3)
    atoms.set_calculator(FakeASE(LennardJones()))

    dyn = BFGS(atoms)
    dyn.run(fmax=0.0005)

    assert dyn.converged()
    assert dyn.get_number_of_steps() == 14
    assert np.linalg.norm(dyn.f0) == pytest.approx(0.0041872094)
コード例 #3
0
ファイル: calculators.py プロジェクト: duartegroup/gap-train
def run_dftb(configuration, max_force, traj_name=None):
    """Run periodic DFTB+ on this configuration. Will set configuration.energy
    and configuration.forces as their calculated values at the TB-DFT level

    --------------------------------------------------------------------------
    :param configuration: (gaptrain.configurations.Configuration)

    :param max_force: (float) or None

    :param traj_name: (str) or None
    """
    from ase.optimize import BFGS

    ase_atoms = configuration.ase_atoms()
    dftb = DFTB(atoms=ase_atoms,
                kpts=(1, 1, 1),
                Hamiltonian_Charge=configuration.charge)

    ase_atoms.set_calculator(dftb)

    try:
        configuration.energy = ase_atoms.get_potential_energy()

        if max_force is not None:
            minimisation = BFGS(ase_atoms, trajectory=traj_name)
            minimisation.run(fmax=float(max_force))
            configuration.n_opt_steps = minimisation.get_number_of_steps()
            set_configuration_atoms_from_ase(configuration, ase_atoms)

    except ValueError:
        raise MethodFailed('DFTB+ failed to generate an energy')

    configuration.forces = ase_atoms.get_forces()

    configuration.partial_charges = ase_atoms.get_charges()

    # Return self to allow for multiprocessing
    return configuration
コード例 #4
0
ファイル: NEB-paral.py プロジェクト: mina-jafari/NEB-scripts
    #combines all images into one file with energies written for each structure
    inFile = open(os.path.join(path, 'structure%03d' % (i, ) + '.xyz'), 'r')
    linesInFile = list()
    for line in inFile:
        linesInFile.append(line)
    numOfLines = len(linesInFile)
    outFile = open(outFileName, 'a')
    outFile.write(linesInFile[0])
    outFile.write(linesInFile[numOfLines - 1])
    for i in range(1, numOfLines - 1):
        outFile.write(linesInFile[i])

#writes the trajectory file in .xyz format
if os.path.exists("gradient"):
    os.remove("gradient")
nsteps = dyn.get_number_of_steps()
for j in range(0, numOfImages):
    traj = PickleTrajectory('neb-%01d.traj' % (j, ))
    path1 = os.getcwd()
    path1 = path1 + '/scratch%01d' % (j, )
    if not os.path.exists(path1): os.makedirs(path1)
    outFileName1 = 'trajectory%03d' % (j, ) + '.xyz'

    fh = open("gradient", 'a')
    fh.write("\n")
    fh.write(str('********neb-%01d.traj' % (j, )))
    fh.write("      Printing information for image %01d **********" %
             ((j + 1), ))
    for i in range(0, nsteps + 1):
        atoms = traj[i]
        string1 = 'structure%03d' % (i, ) + '.xyz'
コード例 #5
0
ファイル: NEB-paral.py プロジェクト: mina-jafari/NEB-scripts
#combines all images into one file with energies written for each structure
    inFile = open(os.path.join(path, 'structure%03d' % (i,) +'.xyz'), 'r')
    linesInFile = list()
    for line in inFile:
        linesInFile.append(line)
    numOfLines = len(linesInFile)
    outFile = open(outFileName, 'a')
    outFile.write(linesInFile[0])
    outFile.write(linesInFile[numOfLines-1])
    for i in range(1, numOfLines-1):
        outFile.write(linesInFile[i])

#writes the trajectory file in .xyz format
if os.path.exists("gradient"):
    os.remove("gradient")
nsteps = dyn.get_number_of_steps()
for j in range(0, numOfImages):
    traj = PickleTrajectory('neb-%01d.traj' % (j,))
    path1 = os.getcwd()
    path1 = path1 + '/scratch%01d' % (j,) 
    if not os.path.exists(path1): os.makedirs(path1)
    outFileName1 = 'trajectory%03d' % (j,) + '.xyz'

    fh = open("gradient", 'a')
    fh.write("\n")
    fh.write(str('********neb-%01d.traj' % (j,)))
    fh.write("      Printing information for image %01d **********" % ((j+1),))
    for i in range(0, nsteps+1):
        atoms = traj[i]
        string1 = 'structure%03d' % (i,) +'.xyz'
        outStruct1 = os.path.join(path1, string1)