예제 #1
0
def plf1(direcs={'ethane': '/home/gfeng/siesta/train/ethane'},
         batch_size=1000):
    for m in direcs:
        mol = m
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft='siesta',
                optword='all',
                batch_size=batch_size,
                rc_scale='none',
                clip_op=False,
                interactive=True)
    molecules = rn.initialize()
    rn.session(learning_rate=1.0e-10, method='AdamOptimizer')

    bd = 'C-C'
    bd1 = 'C-H'
    bd2 = 'H-O'
    f_1 = rn.get_value(rn.f_1)
    f_2 = rn.get_value(rn.f_2)
    f_3 = rn.get_value(rn.f_3)

    # d[natom,nframe] dp[natom,nframe]
    plt.figure()  # temperature
    plt.ylabel(r'f1 distribution')
    plt.xlabel('The value of f1')
    plt.hist(f_1[bd],
             bins=32,
             facecolor='none',
             edgecolor='blue',
             normed=1,
             histtype='step',
             alpha=0.5,
             label=r'$f1(C-C)$')

    plt.hist(f_1[bd1],
             bins=32,
             facecolor='none',
             edgecolor='yellowgreen',
             normed=1,
             histtype='step',
             alpha=0.5,
             label=r'$f1(C-H)$')

    plt.hist(f_1[bd2],
             bins=32,
             facecolor='none',
             edgecolor='red',
             normed=1,
             histtype='step',
             alpha=0.5,
             label=r'$f1(O-H)$')

    plt.legend(loc='best')
    plt.savefig('f1_distribution.eps')
    plt.close()
예제 #2
0
def pldd(direcs={'ethane':'/home/gfeng/siesta/train/ethane'},
         batch_size=50,
         atoms=[8,51]):
    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')

    atom_name = molecules[mol].atom_name
    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_)

    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]

    plt.figure()      
    plt.ylabel(r'$\Delta$ distribution')
    plt.xlabel(r"The value of $\Delta$ and $\Delta'$")
    # plt.xlim(0.01,3.0)
    # plt.ylim(0,50)
    
    for i,atm in enumerate(atoms):
        plt.plot(dp[atm],alpha=0.5,color=colors[(i*2)%len(colors)],
                 label=r"$\Delta^{'}$ of atom@%s:%d" %(atom_name[atm],atm))

        plt.plot(d[atm],alpha=0.5,color=colors[(i*2+1)%len(colors)],
                 label=r'$\Delta$ of atom@%s:%d' %(atom_name[atm],atm))

    plt.legend(loc='best',edgecolor='yellowgreen')
    plt.savefig('delta.eps',transparent=True) 
    plt.close() 
예제 #3
0
def torsion(direcs=None, dft='siesta'):
    for m in direcs:
        mol = m

    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft=dft,
                rc_scale='none',
                optword='all',
                batch_size=200,
                sort=False,
                pkl=True,
                interactive=True)
    rn.initialize()
    rn.session(learning_rate=1.0 - 4, method='AdamOptimizer')
    # rn.plot()

    BOtij = rn.get_value(rn.BOtij)
    BOtjk = rn.get_value(rn.BOtjk)
    BOtkl = rn.get_value(rn.BOtkl)

    f10 = rn.get_value(rn.f_10)
    f11 = rn.get_value(rn.f_11)
    Etor = rn.get_value(rn.Etor)

    torp = rn.torp
    tors = rn.tors
    # print('-  shape of expv2: ',expv2['C'].shape)
    print('-  num of torp %d.' % len(torp))
    print('-  num of tors %d.' % len(tors))
    spec = rn.spec
    torlab = rn.lk.torlab
    ntor = rn.ntor
    tors = rn.tors

    rn.sess.close()

    for tn in tors:
        if ntor[tn] > 0:
            for t in range(ntor[tn]):
                if torlab[tn][t][0] == mol:
                    print('- ', t, tn, 'BOij:', BOtij[tn][t][0], 'BOjk:',
                          BOtjk[tn][t][0], 'BOkl:', BOtkl[tn][t][0], 'f10:',
                          f10[tn][t][0], 'f11:', f11[tn][t][0])

    print('-  shape of Etor:', Etor[mol].shape)
    print('-  num of torp %d.' % len(torp))
    print('-  num of tors %d.' % len(tors))
예제 #4
0
def plddlp(direcs={'ethane': '/home/gfeng/siesta/train/ethane'},
           val='bo2_C-C',
           batch_size=1000):
    for m in direcs:
        mol = m
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft='siesta',
                optword='all',
                batch_size=batch_size,
                rc_scale='none',
                clip_op=False,
                interactive=True)
    molecules = rn.initialize()
    rn.session(learning_rate=1.0e-10, method='AdamOptimizer')

    sp = 'O'
    dlp = rn.get_value(rn.Delta_lp)

    # d[natom,nframe] dp[natom,nframe]
    plt.figure()  # temperature
    plt.ylabel(r'$\Delta$ distribution')
    plt.xlabel(r"The value of $\Delta$ and $\Delta'$")
    n1, bins1, patches1 = plt.hist(dlp[sp],
                                   bins=20,
                                   facecolor='none',
                                   edgecolor='blue',
                                   normed=1,
                                   histtype='step',
                                   alpha=0.5,
                                   label=r"$\Delta_{lp}(O)$")

    plt.legend(loc='best')
    plt.savefig('deltalp_distribution.eps')
    plt.close()
예제 #5
0
def debug_hb(direcs={'ho1': '/home/feng/siesta/train/ho1'}):
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft='siesta',
                rc_scale='none',
                optword='all',
                batch_size=300,
                sort=False,
                pkl=True,
                interactive=True)
    for key in direcs:
        mol = key
    molecules = rn.initialize()
    rn.session(learning_rate=1.0 - 4, method='AdamOptimizer')

    cell = rn.cell[mol]

    A = Atoms(symbols=molecules[mol].atom_name,
              positions=molecules[mol].x[0],
              cell=cell,
              pbc=(1, 1, 1))

    fh = open('hb.txt', 'w')  #### hbond
    fhb = rn.get_value(rn.fhb)
    frhb = rn.get_value(rn.frhb)
    rhb = rn.get_value(rn.rhb)
    ehb = rn.get_value(rn.EHB)
    nhb = rn.nhb

    for hb in rn.hbs:
        if nhb[hb] > 0:
            print('\n-  hbond: %s \n' % hb, file=fh)
            for nb in range(nhb[hb]):
                print('- ',
                      hb,
                      'rhb:',
                      rhb[hb][nb][0],
                      'fhb:',
                      fhb[hb][nb][0],
                      'frhb:',
                      frhb[hb][nb][0],
                      'ehb:',
                      ehb[hb][nb][0],
                      file=fh)
    fh.close()  ###### hbond
예제 #6
0
def get_spv(direcs={'ch4': '/home/gfeng/siesta/train/ch4'}, batch=50):
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft='siesta',
                optword='all',
                batch_size=batch,
                sort=False,
                pkl=True,
                interactive=True)
    rn.initialize()
    rn.session(learning_rate=1.0 - 4, method='AdamOptimizer')

    # ebond = rn.get_value(rn.ebond[mol])
    diffa = rn.get_value(rn.diffa)
    diffb = rn.get_value(rn.diffb)
    diffe = rn.get_value(rn.diffe)
    bosip = rn.get_value(rn.bosip)

    nbd = rn.nbd
    bdlab = rn.lk.bdlab
    bonds = rn.bonds

    fspv = open('spv.txt', 'w')

    for bd in bonds:
        if nbd[bd] > 0:
            print('\n-  spv: %s \n' % bd, file=fspv)
            # for nb in range(nbd[bd]):
            print('- ',
                  bd,
                  'a:',
                  diffa[bd],
                  'b:',
                  diffb[bd],
                  'e:',
                  diffe[bd],
                  's:',
                  bosip[bd],
                  file=fspv)
    fspv.close()

    rn.sess.close()
    del rn
예제 #7
0
def compare_eb(dire):
    system('rm *.pkl')
    mol = 'dp'
    # direcs={mol:dire}
    direcs = {'dp': '/home/gfeng/cpmd/train/nmr/dop'}

    batch = {'others': 10}
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft='cpmd',
                rc_scale='bo1',
                optword='all',
                batch_size=10,
                sort=False,
                pkl=True,
                interactive=True)
    rn.initialize()
    rn.session(learning_rate=1.0 - 4, method='AdamOptimizer')

    dboci = rn.get_value(rn.Di_boc)
    dbocj = rn.get_value(rn.Dj_boc)
    dp = rn.get_value(rn.Dp)
    deltap = rn.get_value(rn.Deltap)
    bop = rn.get_value(rn.BOP)

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

    EBD = rn.get_value(rn.EBD)
    ebd = rn.get_value(rn.ebond)
    ebda = rn.get_value(rn.ebda)

    bdlink = rn.bdlink

    print('-  shape of BOP: ', bop.shape)
    print('-  number of bond: ', rn.lk.nbond)
    print('-  number of atoms: ', len(rn.lk.atom_lab))
    print('-  shape of deltap: ', deltap.shape)
    print('-  shape of ebda: ', ebda[mol].shape)

    nbd = rn.nbd
    bdlab = rn.lk.bdlab
    bdlall = rn.lk.bdlall
    bonds = rn.bonds
    rn.sess.close()
    del rn

    ## another session
    tc = cnn(libfile='ffield',
             direcs=direcs,
             dft='cpmd',
             rc_scale='bo1',
             optword='all',
             batch_size=batch,
             sort=False,
             pkl=True,
             interactive=True)
    tc.session(learning_rate=1.0e-4, method='AdamOptimizer')

    natom = tc.M[mol].molecule.natom
    nbond = tc.M[mol].molecule.nbond
    AN = tc.M[mol].molecule.atom_name
    V = tc.get_value(tc.P[mol]['val'])
    Dp, Db = tc.get_value([tc.M[mol].Deltap, tc.M[mol].Delta_boc])
    Dp = Dp + V

    Powb, Expb, Sieng, EBOND = tc.get_value(
        [tc.M[mol].powb, tc.M[mol].expb, tc.M[mol].sieng, tc.M[mol].EBOND])
    ebond = tc.get_value(tc.M[mol].ebond)

    E = np.zeros([natom, natom])

    for bd in bonds:
        if nbd[bd] > 0:
            # print('-  shape of new style: ',bo[bd].shape)
            print('\n-  bd: %s \n' % bd)
            for nb in range(nbd[bd]):
                if bdlab[bd][nb][0] == mol:
                    iatom = int(bdlab[bd][nb][1])
                    jatom = int(bdlab[bd][nb][2])

                    E[iatom][jatom] = EBD[bd][nb][0]
                    E[jatom][iatom] = EBD[bd][nb][0]

                    if abs(EBOND[0][iatom][jatom] - EBD[bd][nb][0]) > 0.0001:
                        print('- ', bd, iatom, jatom, 'powb:',
                              Powb[0][iatom][jatom], powb[bd][nb][0], 'expb:',
                              Expb[0][iatom][jatom], expb[bd][nb][0], 'sieng:',
                              Sieng[0][iatom][jatom], sieng[bd][nb][0],
                              'EBOND:', EBOND[0][iatom][jatom], EBD[bd][nb][0])
    e = np.sum(E)
    Et = EBOND[0]
    ee = np.sum(Et)
    print('-  ebond:', ebond[0], ebd[mol][0], 'e:', 0.5 * e, 0.5 * ee)
    print('-  number of bond:', len(bdlink[mol]), nbond)
    tc.sess.close()
예제 #8
0
def compare_bo(dire):
    # mol = 'mol'
    # direcs={mol:dire}

    mol = 'mol'
    direcs = {mol: dire}
    # direcs={'nm13':'/home/gfeng/cpmd/train/nmr/nm13',
    #         'nm4':'/home/gfeng/cpmd/train/nmr/nm2004',
    #         'nm11':'/home/gfeng/cpmd/train/nmr/nm11'}

    batch = {'others': 10}
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft='cpmd',
                rc_scale='bo1',
                optword='all',
                batch_size=10,
                sort=False,
                pkl=True,
                interactive=True)
    rn.initialize()
    rn.session(learning_rate=1.0 - 4, method='AdamOptimizer')

    ebondr = rn.get_value(rn.ebond[mol])
    bo = rn.get_value(rn.bo)
    bop = rn.get_value(rn.bop)
    rbd = rn.get_value(rn.rbd)
    bodiv1 = rn.get_value(rn.bodiv1)
    bop_pi = rn.get_value(rn.bop_pi)

    dboci = rn.get_value(rn.Di_boc)
    dbocj = rn.get_value(rn.Dj_boc)
    Dp = rn.get_value(rn.Dp)
    BOP = rn.get_value(rn.BOP)

    nbd = rn.nbd
    bdlab = rn.lk.bdlab
    bonds = rn.bonds
    rn.sess.close()
    del rn

    ## another session
    tc = cnn(libfile='ffield',
             direcs=direcs,
             dft='cpmd',
             rc_scale='bo1',
             optword='all',
             batch_size=batch,
             sort=False,
             pkl=True,
             interactive=True)
    tc.session(learning_rate=1.0e-4, method='AdamOptimizer')

    ebondt = tc.get_value(tc.M[mol].ebond)
    r,BOp,BO,Bodiv1,Bodiv2,Bodiv3,BOp_pi    = \
            tc.get_value([tc.M[mol].r,tc.M[mol].BOp,tc.M[mol].BO,
                          tc.M[mol].bodiv1,tc.M[mol].bodiv2,tc.M[mol].bodiv3,
                          tc.M[mol].BOp_pi])

    Db = tc.get_value(tc.M[mol].Delta_boc)
    Vb = tc.get_value(tc.M[mol].P['valboc'])

    for bd in bonds:
        if nbd[bd] > 0:
            # print('-  shape of new style: ',bo[bd].shape)
            print('\n-  bd: %s \n' % bd)
            for nb in range(nbd[bd]):
                if bdlab[bd][nb][0] == mol:
                    iatom = int(bdlab[bd][nb][1])
                    jatom = int(bdlab[bd][nb][2])
                    if abs(BO[0][iatom][jatom] - bo[bd][nb][0]) > 0.0001:
                        print(
                            '- ',
                            bd,
                            iatom,
                            jatom,
                            'BOp:',
                            BOp[0][iatom][jatom],
                            bop[bd][nb][0],
                            'Dboci:',
                            Db[0][iatom],
                            dboci[bd][nb][0],
                            'Dbocj:',
                            Db[0][jatom],
                            dbocj[bd][nb][0],
                            'BO:',
                            BO[0][iatom][jatom],
                            bo[bd][nb][0],
                        )
    tc.sess.close()
    print('-  shape of BOp: ', BOp.shape)
    print('-  shape of Dp: ', Dp.shape)
예제 #9
0
def compare_f(dire):
    mol = 'mol'
    direcs = {mol: dire}
    batch = {'others': 10}
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft='cpmd',
                rc_scale='bo1',
                optword='all',
                batch_size=10,
                sort=False,
                pkl=True,
                interactive=True)
    rn.initialize()
    rn.session(learning_rate=1.0 - 4, method='AdamOptimizer')
    rn.plot()

    ebondr = rn.get_value(rn.ebond[mol])
    bo = rn.get_value(rn.bo)
    bop = rn.get_value(rn.bop)
    rbd = rn.get_value(rn.rbd)
    bodiv1 = rn.get_value(rn.bodiv1)
    bop_pi = rn.get_value(rn.bop_pi)

    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)

    dboci = rn.get_value(rn.Di_boc)
    dbocj = rn.get_value(rn.Dj_boc)
    Dp = rn.get_value(rn.Dp)
    BOP = rn.get_value(rn.BOP)
    print('-  shape of BOP: ', BOP.shape)
    print('-  number of bond: ', rn.lk.nbond)
    print('-  number of atoms: ', len(rn.lk.atom_lab))

    nbd = rn.nbd
    bdlab = rn.lk.bdlab
    bonds = rn.bonds
    rn.sess.close()
    del rn

    ## another session
    tc = cnn(libfile='ffield',
             direcs=direcs,
             dft='cpmd',
             rc_scale='bo1',
             optword='all',
             batch_size=batch,
             sort=False,
             pkl=True,
             interactive=True)
    tc.session(learning_rate=1.0e-4, method='AdamOptimizer')

    ebondt = tc.get_value(tc.M[mol].ebond)
    r,BOp,BO,Bodiv1,Bodiv2,Bodiv3,BOp_pi    = \
            tc.get_value([tc.M[mol].r,tc.M[mol].BOp,tc.M[mol].BO,
                          tc.M[mol].bodiv1,tc.M[mol].bodiv2,tc.M[mol].bodiv3,
                          tc.M[mol].BOp_pi])

    fbosi = tc.get_value(tc.M[mol].fbosi)

    F,F_11,F_12,F_45,F_4,F_5 = \
             tc.get_value([tc.M[mol].F,tc.M[mol].F_11,tc.M[mol].F_12,tc.M[mol].F_45,
                           tc.M[mol].f_4,tc.M[mol].f_5])

    Db = tc.get_value(tc.M[mol].Delta_boc)
    Vb = tc.get_value(tc.M[mol].P['valboc'])
    print('-  shape of F_11: ', F_11.shape)
    print('-  shape of Delta_boc: ', Db.shape)

    for bd in bonds:
        if nbd[bd] > 0:
            # print('-  shape of new style: ',bo[bd].shape)
            print('\n-  bd: %s \n' % bd)
            for nb in range(nbd[bd]):
                if bdlab[bd][nb][0] == mol:
                    iatom = int(bdlab[bd][nb][1])
                    jatom = int(bdlab[bd][nb][2])
                    if abs(BO[0][iatom][jatom] - bo[bd][nb][0]) > 0.0001:
                        print('- ', bd, iatom, jatom, 'BO:',
                              BO[0][iatom][jatom], bo[bd][nb][0], 'F:',
                              F[0][iatom][jatom], f[bd][nb][0], 'F_11:',
                              F_11[0][iatom][jatom], f11[bd][nb][0], 'F_12:',
                              F_12[0][iatom][jatom], f12[bd][nb][0], 'F_45:',
                              F_45[0][iatom][jatom], f45[bd][nb][0], 'F_4:',
                              F_4[0][iatom][jatom], f4[bd][nb][0], 'F_5:',
                              F_5[0][iatom][jatom], f5[bd][nb][0], 'Dboci:',
                              Db[0][iatom], dboci[bd][nb][0], 'Dbocj:',
                              Db[0][jatom], dbocj[bd][nb][0])
    tc.sess.close()
예제 #10
0
파일: plea.py 프로젝트: trollchu/I-ReaxFF
def plea(direcs={'cwd': getcwd()}, batch_size=200):
    for m in direcs:
        mol = m
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft='siesta',
                optword='all',
                batch_size=batch_size,
                rc_scale='none',
                clip_op=False,
                interactive=True)
    molecules = rn.initialize()
    rn.session(learning_rate=1.0e-10, method='AdamOptimizer')

    D = rn.get_value(rn.D)

    Eov = rn.get_value(rn.EOV)
    Eun = rn.get_value(rn.EUN)
    Elp = rn.get_value(rn.EL)

    atlab = rn.lk.atlab
    natom = molecules[mol].natom

    cell = rn.cell[mol]

    nb_ = 100
    for sp in rn.spec:
        if rn.nsp[sp] > 0:
            plt.figure()  # temperature
            plt.ylabel(r"Distribution Density")
            plt.xlabel(r"Atomic energy (unit: eV)")

            Elp_ = np.reshape(Elp[sp], [-1])
            max_ = np.max(Elp_)
            min_ = np.min(Elp_)
            if min_ < -0.00001:
                hist, bin_ = np.histogram(Elp_,
                                          range=(min_, max_),
                                          bins=nb_,
                                          density=True)
                plt.plot(bin_[:-1],
                         hist,
                         alpha=0.5,
                         color='red',
                         linestyle='-',
                         label=r"lone pair of %s" % bd)

            Eov_ = np.reshape(Eov[sp], [-1])
            max_ = np.max(Eov_)
            min_ = np.min(Eov_)
            if min_ < -0.00001:
                hist, bin_ = np.histogram(Eov_,
                                          range=(min_, max_),
                                          bins=nb_,
                                          density=True)
                plt.plot(bin_[:-1],
                         hist,
                         alpha=0.5,
                         color='green',
                         linestyle='--',
                         label=r"over energy of %s" % sp)

            Eun_ = np.reshape(Eun[sp], [-1])
            max_ = np.max(Eun_)
            min_ = np.min(Eun_)
            if min_ < -0.00001:
                hist, bin_ = np.histogram(Eun_,
                                          range=(min_, max_),
                                          bins=nb_,
                                          density=True)
                plt.plot(bin_[:-1],
                         hist,
                         alpha=0.5,
                         color='blue',
                         linestyle='-.',
                         label=r"under energy of %s" % sp)

            plt.legend(loc='best')
            plt.savefig('eatomic_%s.eps' % sp)
            plt.close()

            print('\n -- %s -- \n' % sp)
            for i in range(rn.nsp[sp]):
                # if Elp[sp][i][0]>0.0:
                print('-  %s D:' % sp, D[sp][i][0], '-  %s Elp:' % sp,
                      Elp[sp][i][0], '-  %s Eov:' % sp, Eov[sp][i][0],
                      '-  %s Eun:' % sp, Eun[sp][i][0])
예제 #11
0
def debug_pen(mol='ch4', direcs={'ch4': '/home/feng/siesta/train/ch4'}):
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft='siesta',
                rc_scale='none',
                optword='all',
                batch_size=1,
                sort=False,
                pkl=True,
                interactive=True)
    molecules = rn.initialize()
    rn.session(learning_rate=1.0 - 4, method='AdamOptimizer')

    # ebond = rn.get_value(rn.ebond[mol])
    bo = rn.get_value(rn.bo)
    bo0 = rn.get_value(rn.bo0)
    bop = rn.get_value(rn.bop)
    rbd = rn.get_value(rn.rbd)
    bodiv1 = rn.get_value(rn.bodiv1)
    bop_pi = rn.get_value(rn.bop_pi)

    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)

    dboci = rn.get_value(rn.Di_boc)
    dbocj = rn.get_value(rn.Dj_boc)
    Dp = rn.get_value(rn.Dp)
    BOP = rn.get_value(rn.BOP)
    # print('-  shape of BOP: ',BOP.shape)

    nbd = rn.nbd
    bdlab = rn.lk.bdlab
    bonds = rn.bonds
    atom_name = molecules[mol].atom_name
    p = rn.p_

    nang = rn.nang
    anglab = rn.lk.anglab
    angs = rn.angs
    cell = rn.cell[mol]

    fbo = open('bo.txt', 'w')
    bd = 'C-C'
    # for bd in bonds:
    if nbd[bd] > 0:
        # print('-  shape of new style: ',bo[bd].shape)
        print('\n-  bd: %s \n' % bd, file=fbo)
        for nb in range(nbd[bd]):
            print('- ',
                  bd,
                  'r:',
                  rbd[bd][nb][0],
                  'BOp:',
                  bop[bd][nb][0],
                  'F:',
                  f[bd][nb][0],
                  'F_11:',
                  f11[bd][nb][0],
                  'F_12:',
                  f12[bd][nb][0],
                  'F_45:',
                  f45[bd][nb][0],
                  'F_4:',
                  f4[bd][nb][0],
                  'F_5:',
                  f5[bd][nb][0],
                  'Dboci:',
                  dboci[bd][nb][0],
                  'Dbocj:',
                  dbocj[bd][nb][0],
                  'BO:',
                  bo0[bd][nb][0],
                  file=fbo)
    fbo.close()

    ff = open('f.txt', 'w')
    f1 = rn.get_value(rn.f_1)
    f2 = rn.get_value(rn.f_2)
    f3 = rn.get_value(rn.f_3)
    dexpf3 = rn.get_value(rn.dexpf3)
    dexpf3t = rn.get_value(rn.dexpf3t)
    f3log = rn.get_value(rn.f3log)

    # for bd in bonds:
    if nbd[bd] > 0:
        print('\n-  bd: %s \n' % bd, file=ff)
        for nb in range(nbd[bd]):
            print('- ',
                  bd,
                  'r:',
                  rbd[bd][nb][0],
                  'f_1:',
                  f1[bd][nb][0],
                  'f_2:',
                  f2[bd][nb][0],
                  'f_3:',
                  f3[bd][nb][0],
                  'dexpf3:',
                  dexpf3[bd][nb][0],
                  'dexpf3t:',
                  dexpf3[bd][nb][0],
                  'f3log:',
                  f3log[bd][nb][0],
                  file=ff)
    ff.close()

    fa = open('ang.txt', 'w')
    eang = rn.get_value(rn.EANG)
    expang = rn.get_value(rn.expang)
    f7 = rn.get_value(rn.f_7)
    f8 = rn.get_value(rn.f_8)
    thet = rn.get_value(rn.thet)
    for a in angs:
        if nang[a] > 0:
            print('\n-  a: %s \n' % bd, file=fa)
            for na in range(nang[a]):
                iat = anglab[a][na][1]
                jat = anglab[a][na][2]
                kat = anglab[a][na][3]
                print('- ',
                      a,
                      'thet:',
                      thet[a][na][0],
                      'f7: ',
                      f7[a][na][0],
                      'f8: ',
                      f8[a][na][0],
                      'expang: ',
                      expang[a][na][0],
                      'eang: ',
                      eang[a][na][0],
                      file=fa)
    fa.close()

    f9 = rn.get_value(rn.f_9)
    epen = rn.get_value(rn.EPEN)
    fijk = rn.get_value(rn.fijk)
    bo = rn.get_value(rn.bo)

    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('/home/feng/gulp/gulp-5.0/Src/gulp<inp-gulp >gulp.out')

    fg = open('gulp.out', 'r')
    for line in fg.readlines():
        if line.find('- epen:') >= 0:
            l = line.split()
            i = int(l[2]) - 1
            j = int(l[3]) - 1
            k = int(l[4]) - 1
            atn = atom_name[i] + '-' + atom_name[j] + '-' + atom_name[k]
            atnk = [mol, i, j, k]
            if not atn in angs:
                atn = atom_name[k] + '-' + atom_name[j] + '-' + atom_name[i]
            atnkr = [mol, k, j, i]

            find = False
            if atnk in anglab[atn]:
                na = anglab[atn].index(atnk)
                find = True
            elif atnkr in anglab[atn]:
                na = anglab[atn].index(atnkr)
                find = True

            if find:
                print('- ReaxFF %s:' % atn, 'f9:', f9[atn][na][0], 'epen:',
                      epen[atn][na][0], fijk[atn][na][0])
                print('-   GULP %s:' % atn, 'f9:', l[9], 'epen:', l[5], l[6])
            else:
                bd1 = atom_name[i] + '-' + atom_name[j]
                bd1k = [mol, i, j]
                if not bd1 in bonds:
                    bd1 = atom_name[j] + '-' + atom_name[i]
                    bd1k = [mol, j, i]

                bd2 = atom_name[i] + '-' + atom_name[k]
                bd2k = [mol, i, k]
                if not bd2 in bonds:
                    bd2 = atom_name[k] + '-' + atom_name[i]
                    bd2k = [mol, k, i]

                if bd1k in bdlab[bd1] and bd2k in bdlab[bd2]:
                    nb1 = bdlab[bd1].index(bd1k)
                    nb2 = bdlab[bd2].index(bd2k)

                    boij = bo[bd1][nb1][0]
                    boik = bo[bd2][nb2][0]
                    print('-   GULP %s:' % atn, l[9], l[5], l[6], 'bo:', bd1,
                          boij, l[10], bd2, boik, l[11])
                else:
                    print('-   GULP %s:' % atn, l[9], l[5], l[6], 'bo:', bd1,
                          'none', l[10], bd2, 'none', l[11])

    fg.close()
예제 #12
0
def debug_be(direcs={'ch4': '/home/feng/siesta/train/ch4'}):
    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')

    bdlab = rn.lk.bdlab
    rbd = rn.get_value(rn.rbd)
    ebond = rn.get_value(rn.EBD)
    sieng = rn.get_value(rn.sieng)
    pieng = rn.get_value(rn.pieng)
    ppeng = rn.get_value(rn.ppeng)

    bosi = rn.get_value(rn.bosi)
    bopi = rn.get_value(rn.bopi)
    bopp = rn.get_value(rn.bopp)

    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('/home/feng/gulp/Src/gulp<inp-gulp >gulp.out')
    atom_name = molecules[mol].atom_name

    fg = open('gulp.out', 'r')
    for line in fg.readlines():
        if line.find('- ebond:') >= 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(ebond[bn][nb][0] - float(l[4])) > 0.001:
                    print('- ReaxFF %s:' % bn, 'rbd:', rbd[bn][nb][0],
                          'ebond:', ebond[bn][nb][0], 'sieng:',
                          sieng[bn][nb][0], 'pieng:', pieng[bn][nb][0],
                          'ppeng:', ppeng[bn][nb][0], 'bosi:', bosi[bn][nb][0],
                          'bopi:', bopi[bn][nb][0], 'bopp:', bopp[bn][nb][0])
                    print('-   GULP %s:' % bn, 'rbd:', l[4], 'ebond:', l[5],
                          'sieng:', l[6], 'pieng:', l[7], 'ppeng:', l[8],
                          'bosi:', l[9], 'bopi:', l[10], 'bopp:', l[11])
    fg.close()
예제 #13
0
def debug_eu(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)
    eunder = rn.get_value(rn.EUN)
    D_lp = rn.get_value(rn.Delta_lpcorr)
    Delta_lp = rn.get_value(rn.Delta_lp)
    DPI = rn.get_value(rn.Dpi)

    eu1 = rn.get_value(rn.eu1)
    eu2 = rn.get_value(rn.eu2)
    expeu2 = rn.get_value(rn.expeu2)
    p = rn.get_value(rn.p)

    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('- eunder:') >= 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),
                      'eunder: %10.6f' % eunder[an][na][0],
                      'eu1: %10.6f' % eu1[an][na][0],
                      'expeu2: %10.6f' % expeu2[an][na][0],
                      'ovun2: %10.6f' % p['ovun2_' + an],
                      'Delta_lp: %10.6f' % Delta_lp[an][na][0],
                      'DPI: %10.6f' % DPI[an][na][0],
                      'Delta_lpcorr: %10.6f' % D_lp[an][na][0])
                print('-   GULP %d %s:' % (na, an),
                      'eunder: %10.6f' % float(l[3]),
                      'eu1: %10.6f' % float(l[5]),
                      'expeu2: %10.6f' % float(l[7]),
                      'ovun2: %10.6f' % float(l[8]),
                      'Delta_lp: %10.6f' % float(l[10]),
                      'DPI: %10.6f' % float(l[11]),
                      'Delta_lpcorr: %10.6f' % float(l[9]))
    fg.close()
예제 #14
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_))
예제 #15
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()
예제 #16
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()
예제 #17
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()
예제 #18
0
def debug_ang(direcs={'cho-4': '/home/feng/siesta/cho4'},
              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')

    f7 = rn.get_value(rn.f_7)
    f8 = rn.get_value(rn.f_8)
    expang = rn.get_value(rn.expang)
    eang = rn.get_value(rn.EANG)
    theta = rn.get_value(rn.theta)
    theta0 = rn.get_value(rn.theta0)
    SBO = rn.get_value(rn.SBO)
    sbo = rn.get_value(rn.sbo)
    pbo = rn.get_value(rn.pbo)
    rnlp = rn.get_value(rn.rnlp)
    D_ang = rn.get_value(rn.D_ang)

    Delta = rn.get_value(rn.Delta)

    atom_name = molecules[mol].atom_name
    p = rn.p_

    nang = rn.nang
    anglab = rn.lk.anglab
    angs = rn.angs
    atom_lab = rn.lk.atom_lab
    cell = rn.cell[mol]
    # print(eang)
    # print(nang)

    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')

    angfind = {}
    for atn in rn.angs:
        angfind[atn] = []

    for line in fg.readlines():
        if line.find('- eval:') >= 0:
            l = line.split()
            i = int(l[2]) - 1
            j = int(l[3]) - 1
            k = int(l[4]) - 1
            atn = atom_name[i] + '-' + atom_name[j] + '-' + atom_name[k]
            atnk = [mol, i, j, k]
            if not atn in angs:
                atn = atom_name[k] + '-' + atom_name[j] + '-' + atom_name[i]
            atnkr = [mol, k, j, i]

            find = False
            if atnk in anglab[atn]:
                na = anglab[atn].index(atnk)
                find = True
            elif atnkr in anglab[atn]:
                na = anglab[atn].index(atnkr)
                find = True

            aj = atom_lab.index([mol, j])

            if find:
                angfind[atn].append(na)
                print('- ReaxFF %s:' % atn, na, atnk, 'sbo:', sbo[atn][na][0],
                      'theta:', theta[atn][na][0], 'theta0:',
                      theta0[atn][na][0], 'expang:', expang[atn][na][0],
                      'eang:', eang[atn][na][0])
                print('-   GULP %s:' % atn, na, atnk, 'sbo:', l[11], 'theta:',
                      l[9], 'theta0:', l[10], 'expang:', l[6], 'eang:', l[5])
            else:
                print('-NF GULP %s:' % atn, na, 'sbo:', l[11], 'theta:', l[9],
                      'theta0:', l[10], 'expang:', l[6], 'eang:', l[5])

    fg.close()

    print('\n-  angles not find\n')

    for atn in rn.angs:
        for na in range(rn.nang[atn]):
            if not na in angfind[atn]:
                al = anglab[atn][na]
                print('- ReaxFF %s:' % atn, na, al, 'sbo:', sbo[atn][na][0],
                      'theta0:', theta0[atn][na][0], 'expang:',
                      expang[atn][na][0], 'eang:', eang[atn][na][0])
예제 #19
0
def pleb(direcs={'cwd': getcwd()}, batch_size=200):
    for m in direcs:
        mol = m
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft='siesta',
                optword='all',
                batch_size=batch_size,
                rc_scale='none',
                clip_op=False,
                interactive=True)
    molecules = rn.initialize()
    rn.session(learning_rate=1.0e-10, method='AdamOptimizer')

    rbd = rn.get_value(rn.rbd)

    Esi = rn.get_value(rn.sieng)
    Epi = rn.get_value(rn.pieng)
    Epp = rn.get_value(rn.ppeng)

    atlab = rn.lk.atlab
    natom = molecules[mol].natom

    cell = rn.cell[mol]

    nb_ = 100

    for bd in rn.bonds:
        if rn.nbd[bd] > 0:
            plt.figure()  # temperature
            plt.ylabel(r"Distribution Density")
            plt.xlabel(r"Bond energy (unit: eV)")

            esi = np.reshape(Esi[bd], [-1])
            max_ = np.max(esi)
            if max_ > 0.1:
                hist, bin_ = np.histogram(esi,
                                          range=(0.1, max_),
                                          bins=nb_,
                                          density=True)
                plt.plot(bin_[:-1],
                         hist,
                         alpha=0.5,
                         color='red',
                         linestyle='-',
                         label=r"$\sigma$ bond of %s" % bd)

            epi = np.reshape(Epi[bd], [-1])
            max_ = np.max(epi)
            if max_ > 0.1:
                hist, bin_ = np.histogram(epi,
                                          range=(0.1, max_),
                                          bins=nb_,
                                          density=True)
                plt.plot(bin_[:-1],
                         hist,
                         alpha=0.5,
                         color='green',
                         linestyle='--',
                         label=r"$\pi$ bond of %s" % bd)

            epp = np.reshape(Epp[bd], [-1])
            max_ = np.max(epp)
            if max_ > 0.1:
                hist, bin_ = np.histogram(epp,
                                          range=(0.1, max_),
                                          bins=nb_,
                                          density=True)
                plt.plot(bin_[:-1],
                         hist,
                         alpha=0.5,
                         color='blue',
                         linestyle='-.',
                         label=r"$\pi\pi$ bond of %s" % bd)

            plt.legend(loc='best')
            plt.savefig('ebond_%s.eps' % bd)
            plt.close()

            print('\n -- %s -- \n' % bd)
            for i in range(rn.nbd[bd]):
                if Esi[bd][i][0] > 0.0:
                    print('-  %s rbd:' % bd, rbd[bd][i][0], '-  %s Esi:' % bd,
                          Esi[bd][i][0], '-  %s Epi:' % bd, Epi[bd][i][0],
                          '-  %s Epp:' % bd, Epp[bd][i][0])
예제 #20
0
def debug_h(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',
                rc_scale='none',
                optword='all',
                batch_size=1,
                sort=False,
                pkl=True,
                interactive=True)
    molecules = rn.initialize()
    rn.session(learning_rate=1.0 - 4, method='AdamOptimizer')

    hblab = rn.lk.hblab
    bdlab = rn.lk.bdlab
    rbd = rn.get_value(rn.rbd)
    rhb = rn.get_value(rn.rhb)
    rik = rn.lk.rik
    rij = rn.lk.rij
    fhb = rn.get_value(rn.fhb)
    frhb = rn.get_value(rn.frhb)
    bohb = rn.get_value(rn.BOhb)
    exphb1 = rn.get_value(rn.exphb1)
    exphb2 = rn.get_value(rn.exphb2)
    sin4 = rn.get_value(rn.sin4)
    hbthe = rn.get_value(rn.hbthe)
    ehb = rn.get_value(rn.EHB)

    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('/home/feng/gulp/gulp-5.0/Src/gulp<inp-gulp >gulp.out')
    system(gulp_cmd)
    # system('/home/gfeng/gulp/gulp-5.0/Src/gulp<inp-gulp >gulp.out')
    atom_name = molecules[mol].atom_name

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

            hb = atom_name[i] + '-' + atom_name[j] + '-' + atom_name[k]
            hbk = [mol, i, j, k]

            bd = atom_name[i] + '-' + atom_name[j]
            if not bd in rn.bonds:
                bd = atom_name[j] + '-' + atom_name[i]
            bdk = [mol, i, j]
            bdkr = [mol, j, i]
            if bdk in bdlab[bd]:
                nbd = bdlab[bd].index(bdk)
            elif bdkr in bdlab[bd]:
                nbd = bdlab[bd].index(bdkr)

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

            if find:
                ib = 0
                for nb in nbs:
                    if abs(rhb[hb][nb][0] - float(l[6])) < 0.00001:
                        print('- ReaxFF %d %s:' % (ib, hb),
                              'rbd: %10.6f' % rbd[bd][nbd][0],
                              'rhb: %10.6f' % rhb[hb][nb][0],
                              'exphb1: %10.6f' % exphb1[hb][nb][0],
                              'bohb: %10.6f' % bohb[hb][nb][0],
                              'exphb2: %10.6f' % exphb2[hb][nb][0],
                              'sin4: %10.6f' % sin4[hb][nb][0],
                              'hbthe: %10.6f' % hbthe[hb][nb][0],
                              'ehb: %10.6f' % ehb[hb][nb][0],
                              'rik: %10.6f' % rik[hb][nb][0])

                        print('-   GULP %d %s:' % (ib, hb),
                              'rbd: %10.6f' % float(l[5]),
                              'rhb: %10.6f' % float(l[6]),
                              'exphb1: %10.6f' % float(l[9]),
                              'bohb: %10.6f' % float(l[13]),
                              'exphb2: %10.6f' % float(l[10]),
                              'sin4: %10.6f' % float(l[11]),
                              'hbthe: %10.6f' % float(l[15]),
                              'ehb: %10.6f' % float(l[12]),
                              'rik: %10.6f' % float(l[14]))
                        ib += 1
            else:
                print('N.F-GULP %s:' % hb, 'rbd: %10.6f' % float(l[5]),
                      'rhb: %10.6f' % float(l[6]), 'fhb: %10.6f' % float(l[7]),
                      'exphb1: %10.6f' % float(l[9]),
                      'bohb: %10.6f' % float(l[13]),
                      'exphb2: %10.6f' % float(l[10]),
                      'sin4: %10.6f' % float(l[11]),
                      'ehb: %10.6f' % float(l[12]))
    fg.close()
예제 #21
0
def debug_plot():
    mol = 'ch4'
    direcs = {mol: '/home/feng/siesta/train/ch4'}

    batch = {'others': 300}
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft='cpmd',
                rc_scale='bo1',
                optword='all',
                batch_size=300,
                sort=False,
                pkl=True,
                interactive=True)
    rn.initialize()
    rn.session(learning_rate=1.0 - 4, method='AdamOptimizer')
    # rn.plot()

    ebondr = rn.get_value(rn.ebond[mol])
    eloner = rn.get_value(rn.elone[mol])
    eoverr = rn.get_value(rn.eover[mol])
    eunderr = rn.get_value(rn.eunder[mol])
    eangr = rn.get_value(rn.eang[mol])
    epenr = rn.get_value(rn.epen[mol])
    tconjr = rn.get_value(rn.tconj[mol])
    etorr = rn.get_value(rn.etor[mol])
    efcon = rn.get_value(rn.efcon[mol])
    evdw = rn.get_value(rn.evdw[mol])

    rn.sess.close()
    del rn

    tc = cnn(libfile='ffield',
             direcs=direcs,
             dft='cpmd',
             rc_scale='bo1',
             optword='all',
             batch_size=batch,
             sort=False,
             pkl=True,
             interactive=True)
    tc.session(learning_rate=1.0e-4, method='AdamOptimizer')
    ebondt = tc.get_value(tc.M[mol].ebond)
    elonet = tc.get_value(tc.M[mol].elone)
    eovert = tc.get_value(tc.M[mol].eover)
    eundert = tc.get_value(tc.M[mol].eunder)
    eangt = tc.get_value(tc.M[mol].eang)
    epent = tc.get_value(tc.M[mol].epen)
    tconjt = tc.get_value(tc.M[mol].tconj)
    etort = tc.get_value(tc.M[mol].etor)
    etort = tc.get_value(tc.M[mol].etor)
    fconj = tc.get_value(tc.M[mol].fconj)
    evdwt = tc.get_value(tc.M[mol].evdw)

    tc.sess.close()

    plot(ebondr, ebondt, 'ebond', 'mol')
    plot(eloner, elonet, 'elone', 'mol')
    plot(eoverr, eovert, 'eover', 'mol')
    plot(eunderr, eundert, 'eunder', 'mol')
    plot(eangr, eangt, 'eang', 'mol')
    plot(epenr, epent, 'epen', 'mol')
    plot(tconjr, tconjt, 'etcon', 'mol')
    plot(etorr, etort, 'etor', 'mol')
    plot(efcon, fconj, 'efcon', 'mol')
    plot(evdw, evdwt, 'evdw', 'mol')
예제 #22
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')
예제 #23
0
def get_v(direcs={'ch4': '/home/gfeng/siesta/train/ch4'}, batch=1):
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft='siesta',
                optword='nocoul',
                batch_size=batch,
                sort=False,
                pkl=True,
                interactive=True)
    rn.initialize()
    rn.session(learning_rate=1.0 - 4, method='AdamOptimizer')

    p = rn.p_
    bo = rn.get_value(rn.bo)
    bo0 = rn.get_value(rn.bo0)
    D = rn.get_value(rn.Deltap)
    Dlp = rn.get_value(rn.Delta_lpcorr)
    bop = rn.get_value(rn.bop)
    rbd = rn.get_value(rn.rbd)
    bodiv1 = rn.get_value(rn.bodiv1)
    bop_pi = rn.get_value(rn.bop_pi)

    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)
    df4 = rn.get_value(rn.df4)
    df5 = rn.get_value(rn.df5)

    dboci = rn.get_value(rn.Di_boc)
    dbocj = rn.get_value(rn.Dj_boc)
    Dp = rn.get_value(rn.Dp)
    BOP = rn.get_value(rn.BOP)
    print('-  shape of BOP: ', BOP.shape)

    nbd = rn.nbd
    bdlab = rn.lk.bdlab
    bonds = rn.bonds

    nang = rn.nang
    anglab = rn.lk.anglab
    angs = rn.angs

    fbo = open('bo.txt', 'w')

    for bd in bonds:
        if nbd[bd] > 0:
            print('\n-  bd: %s \n' % bd, file=fbo)
            for nb in range(nbd[bd]):
                atomi, atomj = bd.split('-')
                print('- ',
                      bd,
                      'r:',
                      rbd[bd][nb][0],
                      'BOp:',
                      bop[bd][nb][0],
                      'F:',
                      f[bd][nb][0],
                      'F_11:',
                      f11[bd][nb][0],
                      'F_12:',
                      f12[bd][nb][0],
                      'F_4:',
                      f4[bd][nb][0],
                      'F_5:',
                      f5[bd][nb][0],
                      'Di:',
                      dboci[bd][nb][0] + p['valboc_' + atomi],
                      'Dj:',
                      dbocj[bd][nb][0] + p['valboc_' + atomj],
                      'BO:',
                      bo0[bd][nb][0],
                      file=fbo)
    fbo.close()

    fa = open('a.txt', 'w')
    for a in rn.spec:
        if rn.nsp[a] > 0:
            print('\n-  specices: %s \n' % a, file=fa)
            for na in range(rn.nsp[a]):
                print(
                    '- ',
                    a,
                    'Dlpc:',
                    Dlp[a][na][0],  # +p['val_'+a],
                    file=fa)
    fa.close()

    ff = open('f.txt', 'w')
    f1 = rn.get_value(rn.f_1)
    f2 = rn.get_value(rn.f_2)
    f3 = rn.get_value(rn.f_3)
    f4 = rn.get_value(rn.f_4)
    f5 = rn.get_value(rn.f_5)
    f4r = rn.get_value(rn.f4r)
    f5r = rn.get_value(rn.f5r)

    dexpf3 = rn.get_value(rn.dexpf3)
    dexpf3t = rn.get_value(rn.dexpf3t)
    f3log = rn.get_value(rn.f3log)

    for bd in bonds:
        if nbd[bd] > 0:
            print('\n-  bd: %s \n' % bd, file=ff)
            for nb in range(nbd[bd]):
                print('- ',
                      bd,
                      'r:',
                      rbd[bd][nb][0],
                      'f_1:',
                      f1[bd][nb][0],
                      'f_2:',
                      f2[bd][nb][0],
                      'f_3:',
                      f3[bd][nb][0],
                      'dexpf3:',
                      dexpf3[bd][nb][0],
                      'dexpf3t:',
                      dexpf3t[bd][nb][0],
                      'f_4:',
                      f4[bd][nb][0],
                      'f_5:',
                      f5[bd][nb][0],
                      'df4:',
                      df4[bd][nb][0],
                      'df5:',
                      df5[bd][nb][0],
                      'f_4r:',
                      f4r[bd][nb][0],
                      'f_5r:',
                      f5r[bd][nb][0],
                      file=ff)
    ff.close()
    rn.sess.close()
    del rn
예제 #24
0
def da(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)

    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'
    anglab = rn.lk.anglab
    angs = []
    for ang in ir.angs:
        angs.append(list(ang))

    ea_ = rn.get_value(rn.EANG)
    ea = ir.eang.numpy()
    f7_ = rn.get_value(rn.f_7)
    f7 = ir.f_7.numpy()
    f8_ = rn.get_value(rn.f_8)
    f8 = ir.f_8.numpy()
    expang_ = rn.get_value(rn.expang)
    expang = ir.expang.numpy()

    expaij_ = rn.get_value(rn.expaij)
    expaij = ir.expaij.numpy()

    expajk_ = rn.get_value(rn.expajk)
    expajk = ir.expajk.numpy()

    theta_ = rn.get_value(rn.theta)
    theta = ir.theta.numpy()
    theta0_ = rn.get_value(rn.theta0)
    theta0 = ir.thet0.numpy()

    sbo3_ = rn.get_value(rn.SBO3)
    sbo3 = ir.SBO3.numpy()

    fa = open('ang.txt', 'w')
    for ang in rn.angs:
        for a_ in range(rn.nang[ang]):
            a = anglab[ang][a_][1:]

            if a not in angs:
                a.reverse()
            i, j, k = a
            if a in angs:
                ai = angs.index(a)
                print('-  %2d%s-%2d%s-%2d%s:' %
                      (i, ir.atom_name[i], j, ir.atom_name[j], k,
                       ir.atom_name[k]),
                      'eang: %10.8f  %10.8f' % (ea_[ang][a_][0], ea[ai]),
                      'f7: %10.8f  %10.8f' % (f7_[ang][a_][0], f7[ai]),
                      'f8: %10.8f  %10.8f' % (f8_[ang][a_][0], f8[ai]),
                      'expang: %10.8f  %10.8f' %
                      (expang_[ang][a_][0], expang[ai]),
                      'expaij: %10.8f  %10.8f' %
                      (expaij_[ang][a_][0], expaij[ai]),
                      'expajk: %10.8f  %10.8f' %
                      (expajk_[ang][a_][0], expajk[ai]),
                      'theta: %10.8f  %10.8f' %
                      (theta_[ang][a_][0], theta[ai]),
                      'sbo3: %10.8f  %10.8f' % (sbo3_[ang][a_][0], sbo3[ai]),
                      'theta0: %10.8f  %10.8f' %
                      (theta0_[ang][a_][0], theta0[ai]),
                      file=fa)
            else:
                print(
                    '-  %2d%s-%2d%s-%2d%s:' %
                    (i, ir.atom_name[i], j, ir.atom_name[j], k,
                     ir.atom_name[k]), 'eang: %10.8f' % (ea_[ang][a_][0]),
                    'f7: %10.8f' % (f7_[ang][a_][0]),
                    'f8: %10.8f' % (f8_[ang][a_][0]),
                    'expang: %10.8f' % (expang_[ang][a_][0]),
                    'expang: %10.8f' % (expang_[ang][a_][0]),
                    'expaij: %10.8f' % (expaij_[ang][a_][0]),
                    'expajk: %10.8f' % (expajk_[ang][a_][0]), 'theta: %10.8f' %
                    (theta_[ang][a_][0]), 'sbo3: %10.8f' % (sbo3_[ang][a_][0]),
                    'theta0: %10.8f' % (theta0_[ang][a_][0]))
    fa.close()
    print('\n-  angel energy:',
          ir.Eang.numpy(),
          rn.eang[mol].numpy()[0],
          end='\n')
예제 #25
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
예제 #26
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]))
예제 #27
0
def compare_u(dire):
    # mol = 'mol'
    # direcs={mol:dire}

    mol = 'nm13'
    #direcs={mol:dire}
    direcs = {
        'nm13': '/home/gfeng/cpmd/train/nmr/nm13',
        'hc': '/home/gfeng/cpmd/train/nmr/hc1',
        'nm4': '/home/gfeng/cpmd/train/nmr/nm2004'
    }

    batch = {'others': 10}
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft='cpmd',
                rc_scale='bo1',
                optword='all',
                batch_size=10,
                sort=False,
                pkl=True,
                interactive=True)
    rn.session(learning_rate=1.0 - 4, method='AdamOptimizer')
    # rn.plot()

    Dpi = rn.get_value(rn.Dpi)
    Dlp = rn.get_value(rn.Delta_lp)
    DLP = rn.get_value(rn.DLP)
    # bpi = rn.get_value(rn.bpi)
    Dlpc = rn.get_value(rn.Delta_lpcorr)

    bopi = rn.get_value(rn.bopi)
    bopp = rn.get_value(rn.bopp)
    D = rn.get_value(rn.D)

    DPI = rn.get_value(rn.DPI)

    print('-  shape of BOPI: ', Dpi['C'].shape)

    spec = rn.spec
    atlab = rn.lk.atlab
    bonds = rn.bonds
    # print('- bonds:\n',bonds)
    nbd = rn.nbd
    bdlab = rn.lk.bdlab
    natom = rn.lk.natom

    rn.sess.close()
    del rn

    ## another session
    tc = cnn(libfile='ffield',
             direcs=direcs,
             dft='cpmd',
             rc_scale='bo1',
             optword='all',
             batch_size=batch,
             sort=False,
             pkl=True,
             interactive=True)
    tc.session(learning_rate=1.0e-4, method='AdamOptimizer')

    # natom = tc.M[mol].molecule.natom
    AN = tc.M[mol].molecule.atom_name
    bonds = tc.bonds

    # print('- bonds:\n',bonds)

    DPI1, Dlp1 = tc.get_value([tc.M[mol].DPI, tc.M[mol].Delta_lp])
    DLP1 = tc.get_value(tc.M[mol].DLP)
    DPI1_ = tc.get_value(tc.M[mol].DPI_)
    Dlpc1 = tc.get_value(tc.M[mol].Delta_lpcorr)
    BO_pi = tc.get_value(tc.M[mol].BO_pi)
    BO_pp = tc.get_value(tc.M[mol].BO_pp)
    Delta = tc.get_value(tc.M[mol].Delta)
    V = tc.get_value(tc.P[mol]['val'])
    Delta += V
    for sp in spec:
        for l, lab in enumerate(atlab[sp]):
            if lab[0] == mol:
                i = int(lab[1])
                print('- ', i, AN[i], 'DPI:', Dpi[sp][l][0], DPI1[0][i],
                      'Dlpc:', Dlpc[sp][l][0], Dlpc1[0][i], 'Delta:',
                      D[sp][l][0], Delta[0][i])

                # 'Dlp:',Dlp[sp][l][0],Dlp1[0][i],

    print('-  shape of DPI: ', DPI.shape)
    tc.sess.close()
예제 #28
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()
예제 #29
0
def ecoul(direcs=None, batch=1, dft='siesta'):
    for m in direcs:
        mol = m

    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft=dft,
                rc_scale='none',
                optword='all',
                batch_size=batch,
                sort=False,
                pkl=True,
                interactive=True)
    molecule = rn.initialize()
    rn.session(learning_rate=1.0 - 4, method='AdamOptimizer')
    # rn.plot()
    vlab = rn.lk.vlab

    ecoul = rn.get_value(rn.ecoul)
    ecou = rn.get_value(rn.ECOU)
    rv = rn.get_value(rn.rv)
    tpv = rn.get_value(rn.tpv)
    qij = rn.get_value(rn.qij)
    rth = rn.get_value(rn.rth)

    bonds = rn.bonds
    nvb = rn.nvb

    for vb in bonds:
        if nvb[vb] > 0:
            for i, r in enumerate(rv[vb]):
                vl = vlab[vb][i]
                vi, vj = vl[1], vl[2]

                found = False
                for j in range(27):
                    R_ = np.array(molecule[mol].R_)
                    tp = np.array(molecule[mol].tp_)
                    qij_ = np.array(molecule[mol].qij)
                    ecoul_ = np.array(molecule[mol].ecoul_)
                    rth_ = np.array(molecule[mol].rth_)

                    if abs(r[0] - R_[j][0][vi][vj]) < 0.000001:
                        nj, i_, j_ = j, vi, vj
                        found = True
                    elif abs(r[0] - R_[j][0][vj][vi]) < 0.000001:
                        nj, i_, j_ = j, vj, vi
                        found = True

                if found:
                    print('-  GULP:', i_, j_, r[0], tpv[vb][i][0],
                          qij[vb][i][0], rth[vb][i][0], ecou[vb][i][0])
                    print('-    IR:', i_, j_, R_[nj][0][i_][j_],
                          tp[nj][0][i_][j_], qij_[0][i_][j_],
                          rth_[nj][0][i_][j_], ecoul_[nj][0][i_][j_],
                          ecoul_[nj][0][j_][i_], R_[nj][0][j_][i_])
                else:
                    print('- not found', vb, i, r[0])
    Ecoul_ = molecule[mol].ecoul

    print('- energys:', ecoul[mol], Ecoul_)
    plt.figure()
    plt.ylabel('Energies')
    plt.xlabel('Step')

    plt.plot(ecoul[mol],
             label=r'$ReaxFF$',
             color='red',
             linewidth=2,
             linestyle='-.')
    plt.plot(Ecoul_,
             label=r'$GULP$',
             color='blue',
             linewidth=2,
             linestyle='--')

    plt.legend()
    plt.savefig('energies_%s.eps' % mol)
    plt.close()
예제 #30
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()