コード例 #1
0
ファイル: MakeGeom.py プロジェクト: QinglangL/inelastica
def repeteANI(ANIinfile, XVinfile, outfile, rep=[1, 1, 1]):
    """Generates a new ANI-file with cell repetitions"""
    GeomList, Energy = SIO.ReadANIFile(ANIinfile)
    initGeom = Geom(XVinfile)
    newGeomList = []
    for i in range(len(GeomList)):
        geom = copy.deepcopy(GeomList[i])
        geom.pbc = N.zeros((3, 3), N.float)
        for i in range(3):
            geom.repeteGeom(initGeom.pbc[i], rep=rep[i])
            geom.pbc[i] = [rep[i] * x for x in initGeom.pbc[i]]
        newGeomList.append(geom)
    SIO.WriteANIFile(outfile, newGeomList, Energy)
コード例 #2
0
ファイル: NEB.py プロジェクト: eminamitani/inelastica-local
def runNEB():
    global general, steps, savedData

    # Restarting?
    fns=glob.glob('NEB_*/CGrun')
    if len(fns)==0:
        restart = False
    elif len(fns)!=general.NNEB:
        sys.exit('Number of NEB_??? directories %i does not match number of steps %i'%(len(fns), general.NNEB))
    else:
        restart=True

    fns = ["NEB_%i/CGrun"%ii for ii in range(general.NNEB)]
    fns = [general.initial+"/CGrun"]+fns+[general.final+"/CGrun"]

    i, f = step(fns[0], False, 0), step(fns[general.NNEB+1], False, general.NNEB+1)
    checkConst(i, f)

    if restart:
        try:
            savedData.E, savedData.F, savedData.Fmax, savedData.geom, savedData.v=pickle.load(open('NEB_%i/savedData.pickle'%0, 'r'))
        except:
            savedData.E    = []
            savedData.F    = []
            savedData.geom = []
            savedData.Fmax = []
            savedData.v    = N.zeros((general.NNEB+2, len(i.XVgeom.xyz), 3), N.float)
    else:
        savedData.E    = []
        savedData.F    = []
        savedData.geom = []
        savedData.Fmax = []
        savedData.v    = N.zeros((general.NNEB+2, len(i.XVgeom.xyz), 3), N.float)

    steps = [step(fn, restart, ii, initial=i, final=f) for ii, fn in enumerate(fns)]

    done=False

    while not done:
        # Start  calculations
        for ii in steps:
            ii.run()

        nextstep=False
        while not nextstep:
            for ii in steps:
                if not ii.checkDone():
                    break
            else:
                nextstep=True
            if not nextstep:
                time.sleep(30)

        savedData.E += [[SIO.GetTotalEnergy(ii.dir+'/RUN.out') for ii in steps]]
        savedData.geom += [[copy.copy(ii.XVgeom) for ii in steps]]

        oldgeom = [copy.deepcopy(ii.XVgeom) for ii in steps]
        for ii, jj in enumerate(steps[1:-1]):
            jj.update(oldgeom[ii], oldgeom[ii+2])

        # Write status
        savedData.F += [[ii.Ftot for ii in steps]]
        savedData.Fmax += [[ii.Fmax for ii in steps]]
        for ii in range(1, len(steps)-1):
            geoms = [savedData.geom[jj][ii] for jj in range(len(savedData.geom))]
            Ftots = [savedData.Fmax[jj][ii] for jj in range(len(savedData.geom))]
            Fs    = [savedData.F[jj][ii] for jj in range(len(savedData.geom))]
            SIO.WriteANIFile('NEB_%i/Steps.ANI'%(ii-1), geoms, Ftots)
            SIO.WriteAXSFFiles('NEB_%i/Steps.XASF'%(ii-1), geoms, forces=Fs)

        geoms = [ii.XVgeom for ii in steps]
        Fmax  = [ii.Fmax for ii in steps]
        Ftot  = [ii.Ftot for ii in steps]
        SIO.WriteANIFile('NEB_%i/NextStep.ANI'%0, geoms, Fmax)
        SIO.WriteAXSFFiles('NEB_%i/NextStep.XASF'%0, geoms, forces=Ftot)
        done = True
        for ii in steps:
            done = done and ii.converged
        pickle.dump((savedData.E, savedData.F, savedData.Fmax, savedData.geom, savedData.v),\
                    open('NEB_%i/savedData.pickle'%0, 'w'))
コード例 #3
0
def runNEB():
    global opts, steps, savedData

    # Restarting?
    fns = glob.glob('NEB_*/CGrun')
    if len(fns) == 0:
        restart = False
    elif len(fns) != opts.NNEB:
        sys.exit(
            'Number of NEB_??? directories %i does not match number of steps %i'
            % (len(fns), opts.NNEB))
    else:
        if opts.onlyInit:
            sys.exit('NEB_* directories already exist, exititng.')
        else:
            restart = True

    fns = ["NEB_%i/CGrun" % ii for ii in range(opts.NNEB)]
    fns = [opts.initial + "/CGrun"] + fns + [opts.final + "/CGrun"]

    i, f = step(fns[0], False, 0), step(fns[opts.NNEB + 1], False,
                                        opts.NNEB + 1)
    if restart:
        try:
            savedData.E, savedData.F, savedData.Fmax, \
                savedData.FmaxWOspring, savedData.geom = pickle.load(open('NEB_0/savedData.pickle', 'r'))
        except:
            savedData.E = []
            savedData.F = []
            savedData.geom = []
            savedData.Fmax = []
    else:
        savedData.E = []
        savedData.F = []
        savedData.geom = []
        savedData.Fmax = []

    steps = [
        step(fn, restart, ii, initial=i, final=f) for ii, fn in enumerate(fns)
    ]

    checkConst(i, f)
    if restart:
        for ii in range(len(steps) - 1):
            checkConst(steps[ii], steps[ii + 1])

    done = opts.onlyInit

    while not done:
        # Start calculations
        for ii in steps:
            ii.run()

        nextstep = False
        while not nextstep:
            for ii in steps:
                if not ii.checkDone():  # Reads forces!
                    break
            else:
                nextstep = True
            if not nextstep:
                time.sleep(10)

        savedData.E += [[
            SIO.GetTotalEnergy(ii.dirr + '/RUN.out') for ii in steps
        ]]
        savedData.geom += [[copy.deepcopy(ii.XVgeom) for ii in steps]]

        overShoot = False
        for ii, jj in enumerate(steps[:-1]):
            if ii != 0:  # Skip first and last
                overShoot = overShoot or jj.shootOver(
                    savedData.geom[-1][ii - 1], savedData.geom[-1][ii + 1])
        if overShoot:  # Kill speed if one image overshoot ... otherwise kinks will appear
            for ii in steps:
                ii.v = ii.v * 0

        for ii, jj in enumerate(steps[:-1]):
            if ii != 0:  # Skip first and last
                jj.update(savedData.geom[-1][ii - 1],
                          savedData.geom[-1][ii + 1])

        # Write status
        savedData.F += [[ii.F for ii in steps]]
        savedData.Fmax += [[ii.Fmax for ii in steps]]
        for ii in range(1, len(steps) - 1):
            geoms = [
                savedData.geom[jj][ii] for jj in range(len(savedData.geom))
            ]
            Fmax = [
                savedData.Fmax[jj][ii] for jj in range(len(savedData.geom))
            ]
            Fs = [savedData.F[jj][ii] for jj in range(len(savedData.geom))]
            SIO.WriteANIFile('NEB_%i/Steps.ANI' % (ii - 1), geoms, Fmax)
            SIO.WriteAXSFFiles('NEB_%i/Steps.XASF' % (ii - 1),
                               geoms,
                               forces=Fs)

        geoms = [ii.XVgeom for ii in steps]
        Fmax = [ii.Fmax for ii in steps]
        F = [ii.F for ii in steps]
        SIO.WriteANIFile('NextStep.ANI', geoms, \
                         [ii-savedData.E[-1][0] for ii in savedData.E[-1]])
        SIO.WriteAXSFFiles('NextStep.XASF', geoms, forces=F)
        done = True
        for ii in steps:
            done = done and ii.converged
        pickle.dump((savedData.E, savedData.F, savedData.Fmax, savedData.geom),\
                    open('NEB_%i/savedData.pickle'%0, 'w'))
        f = open('Convergence', 'a')
        f.write(('####### Iteration %i #######\n#Fmax '+('%2.3f '*(opts.NNEB+2))+'\n')%\
                tuple([len(savedData.Fmax), ]+savedData.Fmax[-1]))
        f.write(('#step length '+(('%2.4f ')*(opts.NNEB+2))+'\n')%\
                tuple([LA.norm(ii.v) for ii in steps]))
        f.write('# Barrier [meV]:\n')
        f.write((('%4.1f '*(opts.NNEB+2))+'\n')%tuple([1000*(savedData.E[-1][ii]-savedData.E[-1][0])\
                                                       for ii in range(opts.NNEB+2)]))
        f.write('# delta E compared to start/restart [meV]:\n')
        f.write((('%4.1f '*(opts.NNEB+2))+'\n')%tuple([1000*(savedData.E[0][ii]-savedData.E[-1][ii])\
                                                       for ii in range(opts.NNEB+2)]))
        f.close()