Esempio n. 1
0
 def run_dih_elem(self, m):
     fnameb = m.name
     coengine_name = "coengine_" + fnameb
     f = open("../Data/Engine/" + coengine_name, 'w')
     #f=open(coengine_name,'w')
     if self._styp == "diha":
         print >> f, "mode opt"
     else:
         print >> f, "mode single"
     print >> f, "infile  " + fnameb + "_inp.pcm"
     print >> f, "outfile " + fnameb + "_out.pcm"
     print >> f, "print 3"
     if self._mm == "mm3":
         print >> f, "forcefield mm3"
         print >> f, "addpar add_MM3.prm"
     elif self._mm == "mmff94":
         print >> f, "forcefield mmff94"
         print >> f, "addpar add_MMFF94.prm"
     else:
         print "Scan.run_scan: Wrong MM-name!"
     f.close()
     #
     timeout = 1
     while True:
         status = run_engine_timeout(self.engine_path, coengine_name,
                                     timeout)
         if status:
             break
         else:
             p, c, ol_templ, lines = read_add(self._mm, self._opt_lin,
                                              self._np, self._nc, 1,
                                              self._styp)
             p[0] += 0.001
             #pert_add_param("add_MM3.prm")
             write_add(self.sdir, p, c, self._mm, ol_templ, lines, 1, None,
                       None)
     #
     comm = "rm ../Data/Engine/" + coengine_name
     #comm="rm "+coengine_name
     system(comm)
Esempio n. 2
0
 def run_dih_elem(self,m):
         fnameb=m.name
         coengine_name="coengine_"+fnameb
         f=open("../Data/Engine/"+coengine_name,'w')
         #f=open(coengine_name,'w')
         if self._styp=="diha":
            print >>f,"mode opt"
         else:
            print >>f,"mode single"
         print >>f,"infile  "+fnameb+"_inp.pcm"
         print >>f,"outfile "+fnameb+"_out.pcm"
         print >>f,"print 3"
         if self._mm=="mm3":
            print >>f,"forcefield mm3"
            print >>f,"addpar add_MM3.prm"
         elif self._mm=="mmff94":
            print >>f,"forcefield mmff94"
            print >>f,"addpar add_MMFF94.prm"
         else:
            print "Scan.run_scan: Wrong MM-name!"
         f.close()
         #
         timeout=1
         while True:
             status=run_engine_timeout(self.engine_path,coengine_name,timeout)
             if status:
                 break
             else:
                 p,c,ol_templ,lines=read_add(self._mm,self._opt_lin,self._np,self._nc,1,self._styp)
                 p[0]+=0.001
                 #pert_add_param("add_MM3.prm")
                 write_add(self.sdir,p,c,self._mm,ol_templ,lines,1,None,None)
         #
         comm="rm ../Data/Engine/"+coengine_name
         #comm="rm "+coengine_name
         system(comm)
Esempio n. 3
0
def pf_run(PF_if):

    scan_type, gopt_type, gopt_s_fnameb, tup, bes, engine_path, mm, mode, alg, ref_p, opt_lin, np, nc, step_int, csv = par_fit_inp(
        PF_if)
    #scan_type=scan_type.strip()

    if engine_path == "":
        engine_path = "../Engine"

    sdir = []
    pref = "../Data/ParFit/" + PF_if
    sdir.append(pref)
    if os.path.exists(pref):
        print
        print 'Warning: The directory', pref, 'exists!'
        print
        sys.exit()
    os.mkdir(pref)
    for gsf in gopt_s_fnameb:
        sd_gsf = pref + "/" + gsf
        sdir.append(sd_gsf)
        os.mkdir(sd_gsf)

    n = len(gopt_type)
    ds = []
    if scan_type == "diha":
        for i in range(n):
            if not bes[i] == ():
                bes[i] = map(int, bes[i])
            sds = DihAScan(sdir, gopt_s_fnameb[i], engine_path, mm, opt_lin,
                           np, nc, bes[i], tup[i])
            ds.append(sds)
    elif scan_type == "bond":
        for i in range(n):
            if not bes[i] == ():
                bes[i] = map(lambda x: 10. * x, bes[i])
                bes[i] = map(int, bes[i])
            sds = BondScan(sdir, gopt_s_fnameb[i], engine_path, mm, opt_lin,
                           np, nc, bes[i], tup[i])
            ds.append(sds)
    elif scan_type == "angl":
        for i in range(n):
            if not bes[i] == ():
                bes[i] = map(lambda x: 10. * x, bes[i])
                bes[i] = map(int, bes[i])
            sds = AnglScan(sdir, gopt_s_fnameb[i], engine_path, mm, opt_lin,
                           np, nc, bes[i], tup[i])
            ds.append(sds)

    if not gopt_type[0] == "ginp":
        os.environ["ENGINE_DIR"] = engine_path + "/engine_dir"
        p, c, ol_templ, lines = read_add(mm, opt_lin, np, nc, 1, scan_type)

    for i in range(n):
        if gopt_type[i] == "full":
            ds[i].read_gamess_outputs()
            ds[i].find_min_ge_key()
        elif gopt_type[i] == "comp":
            ds[i].read_gouts_data()
            ds[i].find_min_ge_key()
        elif gopt_type[i] == "ginp":
            ds[i].write_gamess_inputs()
            ds[i].find_min_ge_key()
            quit()
        else:
            "Par_Fit: Wrong gopt_type!"

        ds[i].write_engine_inputs()

    def engine_rmse(p):

        n = len(ds)
        rmse = 0.
        for i in range(n):
            write_add(sdir, p, c, mm, ol_templ, lines, 1, engine_rmse.step,
                      step_int)
            ds[i].run_scan(p, c, mm, ol_templ)
            rmse += ds[i].calc_rmse(ref_p, csv, i, engine_rmse.step, step_int)
        print engine_rmse.step, round(rmse / n, 4), p

        engine_rmse.step += 1

        return round(rmse / n, 4)

    engine_rmse.step = 1

    def engine_rmse2(p):

        n = len(ds)
        rmse = 0.
        for i in range(n):
            write_add(sdir, p, c, mm, ol_templ, lines, 1, engine_rmse2.step,
                      step_int)
            ds[i].run_scan(p, c, mm, ol_templ)
            rmse += ds[i].calc_rmse(ref_p, csv, i, engine_rmse2.step, step_int)

        engine_rmse2.step += 1

        return (round(rmse / n, 4), )

    engine_rmse2.step = 1

    if mode == "sense":
        eps = 0.01
        np = len(p)
        ppM = numpy.zeros(np)
        ppP = numpy.zeros(np)
        p0 = engine_rmse(p)
        for i in range(np):
            for j in range(np):
                ppM[j] = p[j]
                ppP[j] = p[j]
            ppM[i] -= eps
            ppP[i] += eps
            pM = engine_rmse(ppM)
            pP = engine_rmse(ppP)
            print i + 1, (pM - p0) / eps, (pP - p0) / eps
    else:
        np = len(p)
        if alg == "ga":
            print "Warning: The genetic algorithm printout will not start immediately!"
            hof = run_ga(engine_rmse2, np, 40)
            hof0 = numpy.array(hof[0])
            write_add(sdir, hof0, c, mm, ol_templ, lines, 1, "ga", None)
        elif alg == "fmin":
            #print fmin_powell(engine_rmse,p)
            print fmin(engine_rmse, p, ftol=0.2)
        elif alg == "hybr":
            print "Warning: The genetic algorithm printout will not start immediately!"
            hof = run_ga(engine_rmse2, np, 40)
            hof0 = numpy.array(hof[0])
            write_add(sdir, hof0, c, mm, ol_templ, lines, 1, "ga", None)
            fmin(engine_rmse, hof0, ftol=0.2)
        else:
            "'alg' is not a known algorithm!"
Esempio n. 4
0
def pf_run(PF_if):

    scan_type, gopt_type, gopt_s_fnameb, tup, bes, engine_path, mm, mode, alg, opt_lin, np, nc, step_int, csv = par_fit_inp(
        PF_if
    )
    # scan_type=scan_type.strip()

    if engine_path == "":
        engine_path = "../Engine"

    sdir = []
    pref = "../Data/ParFit/" + PF_if
    sdir.append(pref)
    if os.path.exists(pref):
        print
        print "Warning: The directory", pref, "exists!"
        print
        sys.exit()
    os.mkdir(pref)
    for gsf in gopt_s_fnameb:
        sd_gsf = pref + "/" + gsf
        sdir.append(sd_gsf)
        os.mkdir(sd_gsf)

    n = len(gopt_type)
    ds = []
    if scan_type == "diha":
        for i in range(n):
            if not bes[i] == ():
                bes[i] = map(int, bes[i])
            sds = DihAScan(sdir, gopt_s_fnameb[i], engine_path, mm, opt_lin, np, nc, bes[i], tup[i])
            ds.append(sds)
    elif scan_type == "bond":
        for i in range(n):
            if not bes[i] == ():
                bes[i] = map(lambda x: 10.0 * x, bes[i])
                bes[i] = map(int, bes[i])
            sds = BondScan(sdir, gopt_s_fnameb[i], engine_path, mm, opt_lin, np, nc, bes[i], tup[i])
            ds.append(sds)
    elif scan_type == "angl":
        for i in range(n):
            if not bes[i] == ():
                bes[i] = map(lambda x: 10.0 * x, bes[i])
                bes[i] = map(int, bes[i])
            sds = AnglScan(sdir, gopt_s_fnameb[i], engine_path, mm, opt_lin, np, nc, bes[i], tup[i])
            ds.append(sds)

    if not gopt_type[0] == "ginp":
        os.environ["ENGINE_DIR"] = engine_path + "/engine_dir"
        p, c, ol_templ, lines = read_add(mm, opt_lin, np, nc, 1, scan_type)

    for i in range(n):
        if gopt_type[i] == "full":
            ds[i].read_gamess_outputs()
        elif gopt_type[i] == "comp":
            ds[i].read_gouts_data()
        elif gopt_type[i] == "ginp":
            ds[i].write_gamess_inputs()
            quit()
        else:
            "Par_Fit: Wrong gopt_type!"

        ds[i].write_engine_inputs()

    def engine_rmse(p):

        n = len(ds)
        rmse = 0.0
        for i in range(n):
            write_add(sdir, p, c, mm, ol_templ, lines, 1, engine_rmse.step, step_int)
            ds[i].run_scan(p, c, mm, ol_templ)
            rmse += ds[i].calc_rmse(csv, i, engine_rmse.step, step_int)
        print engine_rmse.step, round(rmse / n, 4), p

        engine_rmse.step += 1

        return round(rmse / n, 4)

    engine_rmse.step = 1

    def engine_rmse2(p):

        n = len(ds)
        rmse = 0.0
        for i in range(n):
            write_add(sdir, p, c, mm, ol_templ, lines, 1, engine_rmse2.step, step_int)
            ds[i].run_scan(p, c, mm, ol_templ)
            rmse += ds[i].calc_rmse(csv, i, engine_rmse2.step, step_int)

        engine_rmse2.step += 1

        return (round(rmse / n, 4),)

    engine_rmse2.step = 1

    if mode == "sense":
        eps = 0.01
        np = len(p)
        ppM = numpy.zeros(np)
        ppP = numpy.zeros(np)
        p0 = engine_rmse(p)
        for i in range(np):
            for j in range(np):
                ppM[j] = p[j]
                ppP[j] = p[j]
            ppM[i] -= eps
            ppP[i] += eps
            pM = engine_rmse(ppM)
            pP = engine_rmse(ppP)
            print i + 1, (pM - p0) / eps, (pP - p0) / eps
    else:
        np = len(p)
        if alg == "ga":
            print "Warning: The genetic algorithm printout will not start immediately!"
            hof = run_ga(engine_rmse2, np, 40)
            hof0 = numpy.array(hof[0])
            write_add(sdir, hof0, c, mm, ol_templ, lines, 1, "ga", None)
        elif alg == "fmin":
            # print fmin_powell(engine_rmse,p)
            print fmin(engine_rmse, p, ftol=0.2)
        elif alg == "hybr":
            print "Warning: The genetic algorithm printout will not start immediately!"
            hof = run_ga(engine_rmse2, np, 40)
            hof0 = numpy.array(hof[0])
            write_add(sdir, hof0, c, mm, ol_templ, lines, 1, "ga", None)
            fmin(engine_rmse, hof0, ftol=0.2)
        else:
            "'alg' is not a known algorithm!"
Esempio n. 5
0
    #print ds.da_rt
    #print ds.dt

    #ds.read_gamess_outputs()
    #ds.write_gouts_data()
    #ds.read_gouts_data()
    #ds.write_engine_inputs()

    #engine_rmse(p)
    default_input_fname="dih_scan_inp"

    gopt_type,gopt_s_fnameb,t1234,bes,engine_path,mm,mode,alg,opt_lin,np,nc,step_int,csv=par_fit_inp(default_input_fname)
    ds=DihScan(gopt_s_fnameb,engine_path,mm,opt_lin,np,nc,bes,t1234)
    if not gopt_type=="ginp":
       environ["ENGINE_DIR"]=engine_path+"engine_dir"
       p,c,ol_templ,lines=read_add(mm,opt_lin,np,nc,1)
  
    def engine_rmse(p):
       print p
       step=1
       step_int=10
       write_add(p,c,mm,ol_templ,lines,1,step,step_int)
       ds.run_scan(p,c,mm,ol_templ,lines)
       rmse=ds.calc_rmse(csv,step,step_int)
       print rmse
       return rmse

    if gopt_type=="full":
       ds.read_gamess_outputs()
    elif gopt_type=="comp":
       ds.read_gouts_data()
Esempio n. 6
0
    #print ds.dt

    #ds.read_gamess_outputs()
    #ds.write_gouts_data()
    #ds.read_gouts_data()
    #ds.write_engine_inputs()

    #engine_rmse(p)
    default_input_fname = "dih_scan_inp"

    gopt_type, gopt_s_fnameb, t1234, bes, engine_path, mm, mode, ref_p, alg, opt_lin, np, nc, step_int, csv = par_fit_inp(
        default_input_fname)
    ds = DihScan(gopt_s_fnameb, engine_path, mm, opt_lin, np, nc, bes, t1234)
    if not gopt_type == "ginp":
        environ["ENGINE_DIR"] = engine_path + "engine_dir"
        p, c, ol_templ, lines = read_add(mm, opt_lin, np, nc, 1)

    def engine_rmse(p):
        print p
        step = 1
        step_int = 10
        write_add(p, c, mm, ol_templ, lines, 1, step, step_int)
        ds.run_scan(p, c, mm, ol_templ, lines)
        rmse = ds.calc_rmse(csv, step, step_int)
        print rmse
        return rmse

    if gopt_type == "full":
        ds.read_gamess_outputs()
    elif gopt_type == "comp":
        ds.read_gouts_data()