示例#1
0
def train_reax(writelib=1000,
               print_step=10,
               step=500,
               opt=None,
               cons=None,
               lr=1.0e-4,
               convergence=0.97,
               lossConvergence=100.0,
               batch=50):
    rn = ReaxFF(libfile='ffield.json',
                direcs=direcs,
                dft='siesta',
                optword='nocoul',
                opt=None,
                cons=None,
                batch_size=batch,
                losFunc='n2',
                lambda_bd=10000.0,
                lambda_me=0.01,
                weight={
                    'al4': 2.0,
                    'others': 2.0
                },
                convergence=convergence,
                lossConvergence=lossConvergence
                )  # Loss Functon can be n2,abs,mse,huber

    # GradientDescentOptimizer AdamOptimizer AdagradOptimizer RMSPropOptimizer
    loss, accu, accMax, i, zpe = rn.run(learning_rate=lr,
                                        step=step,
                                        print_step=print_step,
                                        writelib=writelib)
    libstep = int(i - i % writelib)

    if i == libstep:
        libstep = libstep - writelib
    if libstep <= 0:
        ffd = 'ffield.json'
    else:
        ffd = 'ffield_' + str(libstep) + '.json'

    if loss == 0.0 and accu == 0.0:
        send_msg(
            '-  Warning: the loss is NaN, parameters from %s changed auomatically ...'
            % ffd)
        return 0.0, 1.0, 1.0, None, None, i
        # with open(ffd,'r') as fj:
        #     j = js.load(fj)
        #     ic = Init_Check(nanv=nanv)
        #     j['p'] = ic.auto(j['p'])
        #     ic.close()
        #with open('ffield.json','w') as fj:
        #     js.dump(j,fj,sort_keys=True,indent=2)

    p = rn.p_
    ME = rn.MolEnergy_

    rn.close()
    return loss, accu, accMax, p, ME, i
示例#2
0
def z():
    opt = ['atomic', 'ovun5', 'Desi', 'Depi', 'Depp', 'Devdw', 'Dehb'],
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft='siesta',
                atomic=True,
                optword='nocoul',
                opt=['atomic'],
                nn=False,
                cons=None,
                pkl=True,
                batch_size=batch,
                losFunc='n2',
                bo_penalty=10000.0)

    # tc.session(learning_rate=1.0e-4,method='AdamOptimizer')
    # GradientDescentOptimizer AdamOptimizer AdagradOptimizer RMSPropOptimizer
    rn.run(learning_rate=100, step=1000, print_step=10, writelib=1000)
    rn.close()
示例#3
0
def r():
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft='siesta',
                atomic=True,
                InitCheck=False,
                optword='nocoul',
                VariablesToOpt=vto,
                pkl=True,
                batch_size=batch,
                losFunc='n2',
                bo_penalty=10.0)

    # tc.session(learning_rate=1.0e-4,method='AdamOptimizer')
    # GradientDescentOptimizer AdamOptimizer AdagradOptimizer RMSPropOptimizer
    rn.run(
        learning_rate=1.0e-4,
        step=10000,
        method='AdamOptimizer',  # SGD
        print_step=10,
        writelib=1000)
    rn.close()
示例#4
0
def t():
    opt = ['boc1', 'boc2', 'boc3', 'boc4', 'boc5', 'valboc']
    rn = ReaxFF(libfile='ffield',
                direcs=direcs,
                dft='siesta',
                atomic=True,
                InitCheck=True,
                optword='nocoul',
                VariablesToOpt=vto,
                nn=False,
                bo_layer=[9, 2],
                pkl=True,
                batch_size=batch,
                losFunc='n2',
                bo_penalty=10.0)

    # tc.session(learning_rate=1.0e-4,method='AdamOptimizer')
    # GradientDescentOptimizer AdamOptimizer AdagradOptimizer RMSPropOptimizer
    rn.sa(total_step=1000,
          step=100000,
          astep=3000,
          print_step=10,
          writelib=1000)
    rn.close()
示例#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()