# first geometry
    atomlist = XYZ.read_xyz(geom_file)[0]
    # read charge from title line in .xyz file
    kwds = XYZ.extract_keywords_xyz(geom_file)
    charge = kwds.get("charge", opts.charge)

    pes = PotentialEnergySurfaces(atomlist, charge=charge)
    # dftbaby needs one excited states calculation to set all variables
    x = XYZ.atomlist2vector(atomlist)
    pes.getEnergies(x)

    for i, atomlist in enumerate(XYZ.read_xyz(geom_file)):
        # compute electronic ground state forces with DFTB
        x = XYZ.atomlist2vector(atomlist)
        en = pes.getEnergy_S0(x)
        # total ground state energy including repulsive potential
        en_tot = en[0]
        print("Structure %d   enTot= %s Hartree" % (i, en_tot))
        # electronic energy without repulsive potential
        en_elec = pes.tddftb.dftb2.getEnergies()[2]
        gradVrep, gradE0, gradExc = pes.grads.gradient(I=0)
        # exclude repulsive potential from forces
        grad = gradE0 + gradExc
        forces = XYZ.vector2atomlist(-grad, atomlist)
        if i == 0:
            mode = 'w'
        else:
            mode = 'a'
        print("%2.7f" % en_elec, file=fh_en)
Example #2
0
    # Read the geometry from the xyz-file
    atomlists = XYZ.read_xyz(xyz_file)
    atomlist = atomlists[0]
    # read the charge of the molecule from the comment line in the xyz-file
    kwds = XYZ.extract_keywords_xyz(xyz_file)
    # initialize the TD-DFTB calculator
    pes = PotentialEnergySurfaces(atomlist, Nst=Nst, **kwds)

    fh = open(dat_file, "w")
    for i, atomlist in enumerate(atomlists):
        print "SCAN geometry %d of %d" % (i + 1, len(atomlists))
        # convert geometry to a vector
        x = XYZ.atomlist2vector(atomlist)
        try:
            if Nst == 1:
                ens = pes.getEnergy_S0(x)
            else:
                ens = pes.getEnergies(x)
        except ExcitedStatesError as e:
            print "WARNING: %s" % e
            print "%d-th point is skipped" % i
            continue
        if i == 0:
            E0 = ens[0]
        # subtract ground state energy at first geometry
        ens -= E0
        # convert to eV
        ens *= AtomicData.hartree_to_eV
        print >> fh, "%d  " % i,
        for ei in ens:
            print >> fh, "%3.7f " % ei,