Beispiel #1
0
def debug_eo(direcs={'ch4': '/home/feng/siesta/train/ch4'},
             gulp_cmd='/home/feng/gulp/gulp-5.0/Src/gulp<inp-gulp >gulp.out'):
    for key in direcs:
        mol = key
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft='siesta',
                rc_scale='none',
                clip_op=False,
                optword='all',
                batch_size=1,
                sort=False,
                pkl=True,
                interactive=True)
    molecules = rn.initialize()
    rn.session(learning_rate=1.0 - 4, method='AdamOptimizer')

    atlab = rn.lk.atlab
    rbd = rn.get_value(rn.rbd)
    eover = rn.get_value(rn.EOV)
    D_lp = rn.get_value(rn.Delta_lpcorr)
    otrm1 = rn.get_value(rn.otrm1)
    otrm2 = rn.get_value(rn.otrm2)
    p = rn.get_value(rn.p)
    so = rn.get_value(rn.so)
    cell = rn.cell[mol]
    atom_name = molecules[mol].atom_name

    A = Atoms(symbols=molecules[mol].atom_name,
              positions=molecules[mol].x[0],
              cell=cell,
              pbc=(1, 1, 1))
    write_gulp_in(A, runword='gradient nosymmetry conv qite verb')
    system(gulp_cmd)

    fg = open('gulp.out', 'r')
    for line in fg.readlines():
        if line.find('- eover:') >= 0:
            l = line.split()
            i = int(l[2]) - 1

            an = atom_name[i]
            ank = [mol, i]
            find = False
            if ank in atlab[an]:
                na = atlab[an].index(ank)
                find = True

            if find:
                # if abs(ebond[bn][nb][0]-float(l[4]))>0.001:
                print('- ReaxFF %d %s:' % (na, an),
                      'eover: %10.6f' % eover[an][na][0],
                      'D_lp: %10.6f' % D_lp[an][na][0],
                      'otrm1: %10.6f' % otrm1[an][na][0],
                      'otrm2: %10.6f' % otrm2[an][na][0],
                      'Val: %10.6f' % p['val_' + an],
                      'SO: %10.6f' % so[an][na][0],
                      'ovun2: %10.6f' % p['ovun2_' + an])
                print('-   GULP %d %s:' % (na, an),
                      'eover: %10.6f' % float(l[3]),
                      'D_lp: %10.6f' % float(l[6]),
                      'otrm1: %10.6f' % float(l[5]),
                      'otrm2: %10.6f' % float(l[7]),
                      'Val: %10.6f' % float(l[8]), 'SO: %10.6f' % float(l[4]),
                      'ovun2: %10.6f' % float(l[9]))
            else:
                print('-   GULP %d %s:' % (na, an),
                      'eover: %10.6f' % float(l[3]),
                      'D_lp: %10.6f' % float(l[6]),
                      'otrm1: %10.6f' % float(l[5]),
                      'otrm2: %10.6f' % float(l[7]),
                      'Val: %10.6f' % float(l[8]), 'SO: %10.6f' % float(l[4]),
                      'not found ... ... ... ')
    fg.close()
Beispiel #2
0
def debug_v(direcs={'ch4': '/home/feng/siesta/train/ch4'},
            gulp_cmd='/home/feng/gulp/Src/gulp<inp-gulp >gulp.out'):
    for key in direcs:
        mol = key
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft='siesta',
                optword='nocoul',
                batch_size=1,
                sort=False,
                pkl=True,
                interactive=True)
    molecules = rn.initialize()
    rn.session(learning_rate=1.0 - 4, method='AdamOptimizer')

    vlab = rn.lk.vlab
    rv = rn.get_value(rn.rv)
    expvdw1 = rn.get_value(rn.expvdw1)
    expvdw2 = rn.get_value(rn.expvdw2)
    evdw = rn.get_value(rn.EVDW)
    f13 = rn.get_value(rn.f_13)

    cell = rn.cell[mol]
    A = Atoms(symbols=molecules[mol].atom_name,
              positions=molecules[mol].x[0],
              cell=cell,
              pbc=(1, 1, 1))
    write_gulp_in(A, runword='gradient nosymmetry conv qite verb')
    system(gulp_cmd)
    atom_name = molecules[mol].atom_name

    fg = open('gulp.out', 'r')
    for line in fg.readlines():
        if line.find('- evdw:') >= 0:
            l = line.split()
            i = int(l[2]) - 1
            j = int(l[3]) - 1

            vb = atom_name[i] + '-' + atom_name[j]
            vbk = [mol, i, j]
            vbkr = [mol, j, i]
            if not vb in rn.bonds:
                vb = atom_name[j] + '-' + atom_name[i]

            find = False
            if vbk in vlab[vb]:
                # nb = hblab[hb].index(hbk)
                # print('------------------------------------')
                nbs = []
                for nb, bb in enumerate(vlab[vb]):
                    if bb == vbk:
                        nbs.append(nb)
                find = True
            elif vbkr in vlab[vb]:
                # nb = hblab[hb].index(hbk)
                # print('------------------------------------')
                nbs = []
                for nb, bb in enumerate(vlab[vb]):
                    if bb == vbkr:
                        nbs.append(nb)
                find = True

            if find:
                ib = 0
                for nb in nbs:
                    if abs(rv[vb][nb][0] - float(l[4])) < 0.00001:
                        # if abs(evdw[vb][nb][0]-float(l[5]))>0.0001:
                        print('- ReaxFF %d %s:' % (ib, vb),
                              'rv: %10.6f' % rv[vb][nb][0],
                              'evdw: %10.6f' % evdw[vb][nb][0])

                        print('-   GULP %d %s:' % (ib, vb),
                              'rv: %10.6f' % float(l[4]),
                              'evdw: %10.6f' % float(l[5]))
                        ib += 1
            else:
                print('- N.F GULP %s:' % vb, 'rv: %10.6f' % float(l[4]),
                      'evdw: %10.6f' % float(l[5]))
    fg.close()
Beispiel #3
0
def debug_bo(direcs={'ch4': '/home/feng/siesta/train/ch4'},
             gulp_cmd='/home/feng/gulp/gulp-5.0/Src/gulp<inp-gulp >gulp.out'):
    for key in direcs:
        mol = key
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft='siesta',
                optword='nocoul',
                batch_size=1,
                sort=False,
                pkl=True,
                interactive=True)
    molecules = rn.initialize()
    rn.session(learning_rate=1.0 - 4, method='AdamOptimizer')

    bdlab = rn.lk.bdlab

    bosi = rn.get_value(rn.bosi)

    bo = rn.get_value(rn.bo)
    bo0 = rn.get_value(rn.bo0)

    bop = rn.get_value(rn.bop)
    rbd = rn.get_value(rn.rbd)
    bop_si = rn.get_value(rn.bop_si)
    bop_pi = rn.get_value(rn.bop_pi)
    bop_pp = rn.get_value(rn.bop_pp)

    f = rn.get_value(rn.F)
    f11 = rn.get_value(rn.F_11)
    f12 = rn.get_value(rn.F_12)
    f45 = rn.get_value(rn.F_45)
    f4 = rn.get_value(rn.f_4)
    f5 = rn.get_value(rn.f_5)

    ebond = rn.get_value(rn.ebond)

    cell = rn.cell[mol]

    A = Atoms(symbols=molecules[mol].atom_name,
              positions=molecules[mol].x[0],
              cell=cell,
              pbc=(1, 1, 1))
    write_gulp_in(A, runword='gradient nosymmetry conv qite verb')
    system(gulp_cmd)
    atom_name = molecules[mol].atom_name

    fg = open('gulp.out', 'r')
    for line in fg.readlines():
        if line.find('- bosi:') >= 0:
            l = line.split()
            i = int(l[2]) - 1
            j = int(l[3]) - 1
            bn = atom_name[i] + '-' + atom_name[j]
            if not bn in rn.bonds:
                bn = atom_name[j] + '-' + atom_name[i]
            bnk = [mol, i, j]
            bnkr = [mol, j, i]

            find = False
            if bnk in bdlab[bn]:
                nb = bdlab[bn].index(bnk)
                find = True
            elif bnkr in bdlab[bn]:
                nb = bdlab[bn].index(bnkr)
                find = True

            if find:
                # if abs(rbd[bn][nb][0]-float(l[4]))>0.0001:
                print('- ReaxFF %s:' % bn, 'rbd:', rbd[bn][nb][0], 'bop_si:',
                      bop_si[bn][nb][0], 'bop_pi:', bop_pi[bn][nb][0],
                      'bop_pp:', bop_pp[bn][nb][0])
                print('-   GULP %s:' % bn, 'rbd:', l[4], 'bop_si:', l[5],
                      'bop_pi:', l[6], 'bop_pp:', l[7])
            else:
                print('-   GULP %s:' % bn, 'rbd:', l[4], 'bop_si:', l[5],
                      'bop_pi:', l[6], 'bop_pp:', l[7])
    fg.close()

    e_,eb_,el_,eo_,eu_,ea_,ep_,etc_,et_,ef_,ev_,ehb_,ecl_,esl_= \
            get_reax_energy(fo='gulp.out')

    print('-  ebond - IRFF %f GULP %f.' % (ebond[mol], eb_))
Beispiel #4
0
def plddd(direcs={'ethane': '/home/gfeng/siesta/train/ethane'},
          spec='C',
          nbin=500,
          batch_size=2000):
    for m in direcs:
        mol = m
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft='siesta',
                optword='all',
                batch_size=batch_size,
                clip_op=False,
                interactive=True)
    molecules = rn.initialize()
    rn.session(learning_rate=1.0e-10, method='AdamOptimizer')

    delta = []
    deltap = []

    D = rn.get_value(rn.D)
    atlab = rn.lk.atlab
    natom = molecules[mol].natom
    d = np.zeros([natom, batch_size])
    dp = np.zeros([natom, batch_size])
    cell = rn.cell[mol]

    Dp_ = {}
    for sp in rn.spec:
        if rn.nsp[sp] > 0:
            Dp_[sp] = tf.gather_nd(rn.Deltap, rn.atomlist[sp])
    Dp = rn.get_value(Dp_)

    plt.figure()  # temperature
    plt.ylabel(r'$\Delta$ distribution')
    plt.xlabel(r"The value of $\Delta$ and $\Delta'$")

    hist, bin_ = np.histogram(Dp[spec],
                              range=(np.min(Dp[spec]), np.max(Dp[spec])),
                              bins=nbin,
                              density=True)
    plt.plot(bin_[:-1],
             hist,
             alpha=0.5,
             color='blue',
             linestyle=':',
             label=r"$\Delta^{'}(%s)$ " % spec)

    histp, bin_ = np.histogram(D[spec],
                               range=(np.min(D[spec]), np.max(D[spec])),
                               bins=nbin,
                               density=True)
    plt.plot(bin_[:-1],
             histp,
             alpha=0.5,
             color='yellowgreen',
             linestyle='-.',
             label=r'$\Delta$(%s)' % spec)

    plt.legend(loc='best')
    plt.savefig('delta_%s.eps' % spec)
    plt.close()
Beispiel #5
0
def plbd(direcs={'ethane': '/home/gfeng/siesta/train/ethane'},
         batch_size=50,
         nn=False,
         ffield='ffield',
         bonds=[9, 41]):
    for m in direcs:
        mol = m
    rn = ReaxFF(libfile=ffield,
                direcs=direcs,
                dft='siesta',
                optword='all',
                nn=nn,
                InitCheck=False,
                batch_size=batch_size,
                clip_op=False,
                interactive=True)
    molecules = rn.initialize()
    rn.session(learning_rate=1.0e-10, method='AdamOptimizer')

    rbd = rn.get_value(rn.rbd)
    bop = rn.get_value(rn.bop)
    bo = rn.get_value(rn.bo0)

    bopow1 = rn.get_value(rn.bopow1)
    eterm1 = rn.get_value(rn.eterm1)

    bop_si = rn.get_value(rn.bop_si)
    bosi = rn.get_value(rn.bosi)
    sieng = rn.get_value(rn.sieng)
    powb = rn.get_value(rn.powb)
    expb = rn.get_value(rn.expb)

    bop_pi = rn.get_value(rn.bop_pi)
    bopi = rn.get_value(rn.bopi)

    bop_pp = rn.get_value(rn.bop_pp)
    bopp = rn.get_value(rn.bopp)

    if not nn:
        f11 = rn.get_value(rn.F_11)
        f12 = rn.get_value(rn.F_12)
        f45 = rn.get_value(rn.F_45)
    f = rn.get_value(rn.F)

    bdlab = rn.lk.bdlab
    atom_name = molecules[mol].atom_name
    rn.close()

    bd = bonds
    bdn = atom_name[bd[0]] + '-' + atom_name[bd[1]]
    if not bdn in rn.bonds:
        bdn = atom_name[bd[1]] + '-' + atom_name[bd[0]]
    bn = [mol, bd[0], bd[1]]

    if bn in bdlab[bdn]:
        bid = bdlab[bdn].index(bn)
    else:
        bid = bdlab[bdn].index([mol, bd[1], bd[0]])

    plt.figure()

    plt.subplot(3, 2, 1)
    plt.plot(rbd[bdn][bid],
             alpha=0.5,
             color='b',
             linestyle='-',
             label="radius@%d-%d" % (bd[0], bd[1]))
    plt.legend(loc='best', edgecolor='yellowgreen')

    plt.subplot(3, 2, 2)
    l = len(f[bdn][bid])
    plt.plot(f[bdn][bid],
             alpha=0.5,
             color='r',
             linestyle='-',
             label="F@%d-%d" % (bd[0], bd[1]))
    if nn:
        plt.legend(loc='best', edgecolor='yellowgreen')
    else:
        x_ = int(0.3 * l)
        y_ = f[bdn][bid][x_]
        yt_ = y_ + 0.3 if y_ < 0.5 else y_ - 0.3
        plt.annotate('F',
                     xy=(x_, y_),
                     xycoords='data',
                     xytext=(x_, yt_),
                     arrowprops=dict(arrowstyle='->', facecolor='red'))

    if not nn:
        plt.plot(f11[bdn][bid],
                 alpha=0.5,
                 color='g',
                 linestyle='-.',
                 label="F1@%d-%d" % (bd[0], bd[1]))
        x_ = int(0.6 * l)
        y_ = f11[bdn][bid][x_]
        yt_ = y_ + 0.3 if y_ < 0.5 else y_ - 0.3
        plt.annotate('F1',
                     xy=(x_, y_),
                     xycoords='data',
                     xytext=(x_, yt_),
                     arrowprops=dict(arrowstyle='->', facecolor='red'))

        plt.plot(f45[bdn][bid],
                 alpha=0.5,
                 color='b',
                 linestyle=':',
                 label="F4@%d-%d" % (bd[0], bd[1]))
        x_ = int(0.9 * l)
        y_ = f45[bdn][bid][x_]
        yt_ = y_ + 0.3 if y_ < 0.5 else y_ - 0.3
        plt.annotate('F4',
                     xy=(x_, y_),
                     xycoords='data',
                     xytext=(x_, yt_),
                     arrowprops=dict(arrowstyle='->', facecolor='red'))

    plt.subplot(3, 2, 3)
    plt.plot(bo[bdn][bid],
             alpha=0.5,
             color='b',
             linestyle='-',
             label="BO@%d-%d" % (bd[0], bd[1]))
    plt.legend(loc='best', edgecolor='yellowgreen')

    plt.subplot(3, 2, 4)
    plt.plot(bop_si[bdn][bid],
             alpha=0.5,
             color='b',
             linestyle=':',
             label=r"$BO^{'}_{si}$@%d-%d" % (bd[0], bd[1]))
    plt.plot(bosi[bdn][bid],
             alpha=0.5,
             color='r',
             linestyle='-',
             label=r'$BO_{si}$@%d-%d' % (bd[0], bd[1]))
    plt.legend(loc='best', edgecolor='yellowgreen')

    plt.subplot(3, 2, 5)
    plt.plot(sieng[bdn][bid],
             alpha=0.5,
             color='b',
             linestyle='-',
             label=r"$ebond_{si}$@%d-%d" % (bd[0], bd[1]))
    plt.legend(loc='best', edgecolor='yellowgreen')

    plt.subplot(3, 2, 6)
    plt.plot(powb[bdn][bid],
             alpha=0.5,
             color='b',
             linestyle='-',
             label=r"$pow_{si}$@%d-%d" % (bd[0], bd[1]))
    plt.plot(expb[bdn][bid],
             alpha=0.5,
             color='r',
             linestyle='-',
             label=r"$exp_{si}$@%d-%d" % (bd[0], bd[1]))
    plt.legend(loc='best', edgecolor='yellowgreen')

    # plt.subplot(3,2,6)
    # # plt.ylabel(r'$exp$ (eV)')
    # plt.xlabel(r"Step")
    # plt.plot(eterm1[bdn][bid],alpha=0.5,color='b',
    #          linestyle='-',label=r"$exp_{si}$@%d-%d" %(bd[0],bd[1]))
    # plt.legend(loc='best',edgecolor='yellowgreen')

    plt.savefig('bondorder.eps', transparent=True)
    plt.close()
Beispiel #6
0
def plot_delta(direcs=None, batch_size=1, dft='siesta'):
    for m in direcs:
        mol = m
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft=dft,
                opt=[],
                optword='all',
                batch_size=batch_size,
                rc_scale='none',
                interactive=True)
    molecules = rn.initialize()
    rn.session(learning_rate=1.0e-10, method='AdamOptimizer')
    D = rn.get_value(rn.D)
    Dlp = rn.get_value(rn.Dlp)

    Dp_ = {}
    for sp in rn.spec:
        if rn.nsp[sp] > 0:
            Dp_[sp] = tf.gather_nd(rn.Deltap, rn.atomlist[sp])
    Dp = rn.get_value(Dp_)

    atlab = rn.lk.atlab

    traj = Trajectory('delta.traj', 'w')
    trajp = Trajectory('deltap.traj', 'w')
    trajlp = Trajectory('deltalp.traj', 'w')

    natom = molecules[mol].natom
    d = np.zeros([natom, batch_size])
    dp = np.zeros([natom, batch_size])
    dlp = np.zeros([natom, batch_size])
    cell = rn.cell[mol]

    for sp in rn.spec:
        if rn.nsp[sp] > 0:
            for l, lab in enumerate(atlab[sp]):
                if lab[0] == mol:
                    i = int(lab[1])
                    d[i] = D[sp][l]
                    dp[i] = Dp[sp][l]
                    dlp[i] = Dlp[sp][l]

    for nf in range(batch_size):
        A = Atoms(symbols=molecules[mol].atom_name,
                  positions=molecules[mol].x[nf],
                  charges=d[:, nf],
                  cell=cell,
                  pbc=(1, 1, 1))
        traj.write(A)

        Ap = Atoms(symbols=molecules[mol].atom_name,
                   positions=molecules[mol].x[nf],
                   charges=dp[:, nf],
                   cell=cell,
                   pbc=(1, 1, 1))
        trajp.write(Ap)

        Alp = Atoms(symbols=molecules[mol].atom_name,
                    positions=molecules[mol].x[nf],
                    charges=dlp[:, nf],
                    cell=cell,
                    pbc=(1, 1, 1))
        trajlp.write(Alp)
    traj.close()
    trajp.close()
    trajlp.close()
Beispiel #7
0
def dh(traj='siesta.traj',batch_size=1,nn=True,frame=7):
    ffield = 'ffield.json' if nn else 'ffield'
    images = Trajectory(traj)
    atoms  = images[frame]
    his    = TrajectoryWriter('tmp.traj',mode='w')
    his.write(atoms=atoms)
    his.close()

    from irff.irff import IRFF
    ir = IRFF(atoms=atoms,
              libfile=ffield,
              nn=nn,
              bo_layer=[9,2])
    ir.get_potential_energy(atoms)
    
    from irff.reax import ReaxFF
    rn = ReaxFF(libfile=ffield,
                direcs={'tmp':'tmp.traj'},
                dft='siesta',
                opt=[],optword='nocoul',
                batch_size=batch_size,
                atomic=True,
                clip_op=False,
                InitCheck=False,
                nn=nn,
                pkl=False,
                to_train=False) 
    molecules = rn.initialize()
    rn.session(learning_rate=1.0e-10,method='AdamOptimizer')

    mol    = 'tmp'
    hblab  = rn.lk.hblab
    hbs    = []

    for hb in ir.hbs:
        hbs.append(list(hb))

    eh_    = rn.get_value(rn.EHB) 
    # eh     = ir.ehb.numpy()
    rhb_   = rn.get_value(rn.rhb) 
    # rhb    = ir.rhb.numpy()

    frhb_  = rn.get_value(rn.frhb) 
    # frhb   = ir.frhb.numpy()

    sin4_  = rn.get_value(rn.sin4) 
    # sin4   = ir.sin4.numpy()

    # exphb1_= rn.get_value(rn.exphb1) 
    # exphb2_= rn.get_value(rn.exphb2) 

    # exphb1 = ir.exphb1.numpy()
    # exphb2 = ir.exphb2.numpy()

    # hbsum_ = rn.get_value(rn.hbsum) 
    # hbsum  = ir.hbsum.numpy()

    for hb in rn.hbs:
        for a_ in range(rn.nhb[hb]):
            a = hblab[hb][a_][1:]
            i,j,k = a

            if a in hbs:
               ai = hbs.index(a)
               # if eh_[hb][a_][0]<-0.000001:
               print('-  %2d%s-%2d%s-%2d%s:' %(i,ir.atom_name[i],j,ir.atom_name[j],k,ir.atom_name[k]),
                   'ehb: %10.8f' %(eh_[hb][a_][0]), 
                   'rhb: %10.8f' %(rhb_[hb][a_][0]), 
                  'frhb: %10.8f' %(frhb_[hb][a_][0]), 
                  'sin4: %10.8f' %(sin4_[hb][a_][0]) )
Beispiel #8
0
def plov(direcs={'ethane':'/home/gfeng/siesta/train/ethane'},
         atoms=[8,51],
         batch_size=2000):
    for m in direcs:
        mol = m
    rn = ReaxFF(libfile='ffield',direcs=direcs,dft='siesta',
                 optword='all',
                 batch_size=batch_size,
                 clip_op=False,
                 pkl=False,
                 InitCheck=False,
                 interactive=True) 
    molecules = rn.initialize()
    rn.session(learning_rate=1.0e-10,method='AdamOptimizer')

    atom_name = molecules[mol].atom_name

    D     = rn.get_value(rn.D)
    Dp    = rn.get_value(rn.Delta_lpcorr)
    Dl    = rn.get_value(rn.Delta_lp)
    De    = rn.get_value(rn.Delta_e)
    NLP   = rn.get_value(rn.nlp)
    Eov   = rn.get_value(rn.EOV)

    atlab = rn.lk.atlab
    natom = molecules[mol].natom
    d     = np.zeros([natom,batch_size])
    dlc   = np.zeros([natom,batch_size])
    dl    = np.zeros([natom,batch_size])
    de    = np.zeros([natom,batch_size])
    nlp   = np.zeros([natom,batch_size])
    eov   = np.zeros([natom,batch_size])
    cell  = rn.cell[mol]
    p     = rn.p_

    for sp in rn.spec:
        if rn.nsp[sp]>0:
           for l,lab in enumerate(atlab[sp]):
               if lab[0]==mol:
                  i = int(lab[1])
                  d[i]   = D[sp][l]
                  dlc[i] = Dp[sp][l]
                  dl[i]  = Dl[sp][l]
                  de[i]  = 2.0*De[sp][l]
                  nlp[i] = NLP[sp][l]
                  eov[i] = Eov[sp][l]

    plt.figure()      

    plt.subplot(3,2,1)    
    # plt.ylabel(r'$\Delta_{lpcorr}$')
    # plt.xlabel(r"Step")
    
    for i,atm in enumerate(atoms):
        plt.plot(d[atm],alpha=0.5,color=colors[(i)%len(colors)],
                 label=r"$\Delta$@%s:%d" %(atom_name[atm],atm))
    plt.legend(loc='best',edgecolor='yellowgreen')

    plt.subplot(3,2,2)    
    # plt.ylabel(r'$\Delta_{lpcorr}$')
    # plt.xlabel(r"Step")
    
    for i,atm in enumerate(atoms):
        plt.plot(dlc[atm],alpha=0.5,color=colors[(i)%len(colors)],
                 label=r"$\Delta_{lpcorr}$@%s:%d" %(atom_name[atm],atm))
    plt.legend(loc='best',edgecolor='yellowgreen')

    plt.subplot(3,2,3)    
    # plt.ylabel(r'$\Delta_{lp}$')
    # plt.xlabel(r"Step")
    for i,atm in enumerate(atoms):
        plt.plot(dl[atm],alpha=0.5,color=colors[(i)%len(colors)],
                 label=r"$\Delta_{lp}$@%s:%d" %(atom_name[atm],atm))
    plt.legend(loc='best',edgecolor='yellowgreen')

    plt.subplot(3,2,4)    
    # plt.ylabel(r'$\Delta_e$')
    plt.xlabel(r"Step")
    for i,atm in enumerate(atoms):
        plt.plot(de[atm],alpha=0.5,color=colors[(i)%len(colors)],
                 label=r'$\Delta_e$@%s:%d' %(atom_name[atm],atm))
    plt.legend(loc='best',edgecolor='yellowgreen')

    plt.subplot(3,2,5)    
    # plt.ylabel(r'$Eover$')
    plt.xlabel(r"Step")
    for i,atm in enumerate(atoms):
        plt.plot(nlp[atm],alpha=0.5,color=colors[(i)%len(colors)],
                 label=r"$NLP$@%s:%d" %(atom_name[atm],atm))
    plt.legend(loc='best',edgecolor='yellowgreen')

    plt.subplot(3,2,6)    
    # plt.ylabel(r'$Eover$')
    plt.xlabel(r"Step")
    for i,atm in enumerate(atoms):
        plt.plot(dlc[atm]+p['val_'+atom_name[atm]],alpha=0.5,color=colors[(i)%len(colors)],
                 label=r"$\Delta_{lpcorr}+val$@%s:%d" %(atom_name[atm],atm))
    plt.legend(loc='best',edgecolor='yellowgreen')

    plt.savefig('Delta_lpcorr.eps',transparent=True) 
    plt.close() 
Beispiel #9
0
def dt(traj='siesta.traj', batch_size=1, nn=True, frame=0):
    ffield = 'ffield.json' if nn else 'ffield'
    images = Trajectory(traj)
    atoms = images[frame]
    his = TrajectoryWriter('tmp.traj', mode='w')
    his.write(atoms=atoms)
    his.close()

    from irff.irff import IRFF
    ir = IRFF(atoms=atoms, libfile=ffield, nn=nn)
    ir.get_potential_energy(atoms)
    eb = ir.Ebond.numpy()

    et = ir.etor.numpy()
    ef = ir.efcon.numpy()
    f10 = ir.f_10.numpy()
    f11 = ir.f_11.numpy()

    sijk = ir.s_ijk.numpy()
    sjkl = ir.s_jkl.numpy()

    f = ir.fijkl.numpy()
    v1 = ir.v1.numpy()
    v2 = ir.v2.numpy()
    v3 = ir.v3.numpy()

    expv2 = ir.expv2.numpy()

    boij = ir.botij.numpy()
    bojk = ir.botjk.numpy()
    bokl = ir.botkl.numpy()

    cosw = ir.cos_w.numpy()
    cos2w = ir.cos2w.numpy()
    w = ir.w.numpy()

    Etor = ir.Etor.numpy()
    del IRFF

    from irff.reax import ReaxFF
    rn = ReaxFF(libfile=ffield,
                direcs={'tmp': 'tmp.traj'},
                dft='siesta',
                opt=[],
                optword='nocoul',
                batch_size=batch_size,
                atomic=True,
                clip_op=False,
                InitCheck=False,
                nn=nn,
                bo_layer=[9, 2],
                pkl=False,
                to_train=False)
    molecules = rn.initialize()
    # rn.calculate(rn.p,rn.m)
    rn.session(learning_rate=3.0 - 4, method='AdamOptimizer')

    mol = 'tmp'
    torlab = rn.lk.torlab
    tors = []
    for tor in ir.tors:
        tors.append(list(tor))
        print(tor)

    eb_ = rn.get_value(rn.ebond[mol])
    et_ = rn.get_value(rn.ETOR)
    ef_ = rn.get_value(rn.Efcon)
    f10_ = rn.get_value(rn.f_10)
    f11_ = rn.get_value(rn.f_11)

    sijk_ = rn.get_value(rn.s_ijk)
    sjkl_ = rn.get_value(rn.s_jkl)

    f_ = rn.get_value(rn.fijkl)

    boij_ = rn.get_value(rn.BOtij)
    bojk_ = rn.get_value(rn.BOtjk)
    bokl_ = rn.get_value(rn.BOtkl)

    v1_ = rn.get_value(rn.v1)
    v2_ = rn.get_value(rn.v2)
    v3_ = rn.get_value(rn.v3)

    expv2_ = rn.get_value(rn.expv2)

    cosw_ = rn.get_value(rn.cos_w)
    cos2w_ = rn.get_value(rn.cos2w)
    w_ = rn.get_value(rn.w)

    for tor in rn.tors:
        for a_ in range(rn.ntor[tor]):
            a = torlab[tor][a_][1:]

            if a not in tors:
                a.reverse()
            i, j, k, l = a
            if a in tors:
                ai = tors.index(a)
                # if abs(et_[tor][a_][0]-et[ai])>0.0001:
                print(
                    '-  %2d%s-%2d%s-%2d%s-%2d%s:' %
                    (i, ir.atom_name[i], j, ir.atom_name[j], k,
                     ir.atom_name[k], l, ir.atom_name[l]),
                    'etor: %10.8f  %10.8f' % (et_[tor][a_][0], et[ai]),
                    'sijk: %10.8f  %10.8f' % (sijk_[tor][a_][0], sijk[ai]),
                    'sjkl: %10.8f  %10.8f' % (sjkl_[tor][a_][0], sjkl[ai]),
                    'boij: %10.8f  %10.8f' % (boij_[tor][a_][0], boij[ai]),
                    'bojk: %10.8f  %10.8f' % (bojk_[tor][a_][0], bojk[ai]),
                    'bokl: %10.8f  %10.8f' % (bokl_[tor][a_][0], bokl[ai]),
                    'fijkl: %10.8f  %10.8f' % (f_[tor][a_][0], f[ai]),
                    'v1: %10.8f  %10.8f' % (v1_[tor][a_][0], v1[ai]),
                    'v2: %10.8f  %10.8f' % (v2_[tor][a_][0], v2[ai]),
                    'v3: %10.8f  %10.8f' % (v3_[tor][a_][0], v3[ai]),
                    'expv2: %10.8f  %10.8f' % (expv2_[tor][a_][0], expv2[ai]),
                    'ptor1: %10.8f  %10.8f' %
                    (rn.p_['tor1_' + tor], ir.P['tor1'][ai]),
                    # 'cosw: %10.8f  %10.8f' %(cosw_[tor][a_][0],cosw[ai]),
                    # 'cos2w: %10.8f  %10.8f' %(cos2w_[tor][a_][0],cos2w[ai]),
                    #  'v1: %10.8f  %10.8f' %(0.5*rn.p_['V1_'+tor]*(1.0+cosw_[tor][a_][0]),
                    #                         0.5*ir.P['V1'][ai]*(1.0+cosw[ai])),
                    #  'w: %10.8f  %10.8f' %(w_[tor][a_][0],w[ai]),
                    # 'efcon: %10.8f  %10.8f' %(ef_[tor][a_][0],ef[ai]),
                    #  'f_10: %10.8f  %10.8f' %(f10_[tor][a_][0],f10[ai]),
                    #  'f_11: %10.8f  %10.8f' %(f11_[tor][a_][0],f11[ai]),
                )
    Etor_ = rn.get_value(rn.etor)
    print('\n-  torsion energy:', Etor, Etor_[mol][0], end='\n')
    print('\n-  Bond energy:', eb, eb_, end='\n')
    del ReaxFF
Beispiel #10
0
def dl(traj='siesta.traj', batch_size=1, nn=False, frame=0):
    ffield = 'ffield.json' if nn else 'ffield'
    images = Trajectory(traj)
    atoms = images[frame]
    his = TrajectoryWriter('tmp.traj', mode='w')
    his.write(atoms=atoms)
    his.close()

    ir = IRFF(atoms=atoms, libfile=ffield, nn=False, bo_layer=[8, 4])

    ir.get_potential_energy(atoms)
    el = ir.elone.numpy()
    Dle = ir.Delta_e.numpy()
    Dlp = ir.Delta_lp.numpy()
    de = ir.DE.numpy()
    nlp = ir.nlp.numpy()
    elp = ir.explp.numpy()
    eu = ir.eunder.numpy()
    eu1 = ir.eu1.numpy()
    eu2 = ir.eu2.numpy()
    eu3 = ir.expeu3.numpy()

    rn = ReaxFF(libfile=ffield,
                direcs={'tmp': 'tmp.traj'},
                dft='siesta',
                opt=[],
                optword='nocoul',
                batch_size=batch_size,
                atomic=True,
                clip_op=False,
                InitCheck=False,
                nn=nn,
                pkl=False,
                to_train=False)
    molecules = rn.initialize()
    rn.session(learning_rate=1.0e-10, method='AdamOptimizer')

    mol = 'tmp'
    el_ = rn.get_value(rn.EL)
    Dle_ = rn.get_value(rn.Delta_e)
    Dlp_ = rn.get_value(rn.Delta_lp)
    de_ = rn.get_value(rn.DE)
    nlp_ = rn.get_value(rn.nlp)
    elp_ = rn.get_value(rn.explp)

    eu_ = rn.get_value(rn.EUN)
    eu1_ = rn.get_value(rn.eu1)
    eu2_ = rn.get_value(rn.eu2)
    eu3_ = rn.get_value(rn.expeu3)

    alab = rn.lk.atlab
    bosi = ir.bosi.numpy()

    for i in range(ir.natom):
        a = ir.atom_name[i]
        al = [mol, i]
        na = alab[a].index(al)
        print(
            '-  %d %s:' % (i, ir.atom_name[i]),
            'elone: %10.8f  %10.8f' % (el_[a][na], el[i]),
            #  'Delta_e: %10.8f  %10.8f' %(Dle_[a][na],Dle[i]),
            # 'Delta_lp: %10.8f  %10.8f' %(Dlp_[a][na],Dlp[i]),
            #      'nlp: %10.8f  %10.8f' %(nlp_[a][na],nlp[i]),
            'eunder: %10.8f  %10.8f' % (eu_[a][na], eu[i]),
            #    'eu1: %10.8f  %10.8f' %(eu1_[a][na],eu1[i]),
            'eu2: %10.8f  %10.8f' % (eu2_[a][na], eu2[i]),
            'eu3: %10.8f  %10.8f' % (eu3_[a][na], eu3[i]))
    print('\n-  under energy:',
          ir.Eunder.numpy(),
          rn.eunder[mol].numpy()[0],
          end='\n')