예제 #1
0
파일: parmfit.py 프로젝트: lidaobing/itcc
def parmfit(datfname, idxfname, param):
    fnames, enes, weights = tools.readdat(datfname)
    idxs, folds = readidx(idxfname)
    params = getparams(idxs, param)
    A = []
    B = []
    for fname, E_qm, weight in zip(fnames, enes, weights):
        mol = read.readxyz(file(fname))
        tors = analyze.gettorsbytype(mol, idxs)
        newmol, E_mm = tinker.minimize_file(fname, param)
        E_tor = getetor(newmol, tors, params)
        E_fit = E_qm - E_mm + E_tor
        weight = math.sqrt(weight)
        B.append(E_fit * weight)
        A.append([x*weight for x in getA(newmol, idxs, folds, tors)])
    A = numpy.array(A)
    B = numpy.array(B)

    result = numpy.linalg.lstsq(A, B)
    newparam = list(result[0][:-1])
    errors = numpy.dot(A, result[0]) - B
    errors = [error/math.sqrt(weight) for error, weight in zip(errors, weights)]
    error = extra_tools.weightedsd(errors, weights)
    printprm(newparam, idxs, folds)
    print error
예제 #2
0
파일: printefit.py 프로젝트: lidaobing/itcc
def printefit(datfname, idxfname, param):
    '''Only print E_fit'''
    import csv
    fnames, enes, weights = tools.readdat(datfname)
    idxs, folds = parmfit.readidx(idxfname)
    params = parmfit.getparams(idxs, param)
    writer = csv.writer(sys.stdout)
    writer.writerow(['Filename', 'weight', 'E_qm', 'E_mm', 'E_tor', 'E_fit'])
    for fname, E_qm, weight in zip(fnames, enes, weights):
        mol = read.readxyz(file(fname))
        tors = analyze.gettorsbytype(mol, idxs)
        newmol, E_mm = tinker.minimize_file(fname, param)
        E_tor = parmfit.getetor(newmol, tors, params)
        E_fit = E_qm - E_mm + E_tor
        writer.writerow([fname, weight, E_qm, E_mm, E_tor, E_fit])
예제 #3
0
파일: parmeval.py 프로젝트: lidaobing/itcc
def parmeval(datfname, param):
    fnames, enes, weights = tortools.readdat(datfname)
    writer = csv.writer(sys.stdout)
    writer.writerow(['Filename', 'weight', 'E_qm', 'E_mm', 'E_diff', 'RMSD'])
    E_diffs = []
    rmsds = []
    for fname, E_qm, weight in zip(fnames, enes, weights):
        mol = read.readxyz(file(fname))
        newmol, E_mm = tinker.minimize_file(fname, param)
        E_diff = E_mm - E_qm
        E_diffs.append(E_diff)
        rmsd_ = rmsd.rmsd(mol, newmol)
        rmsds.append(rmsd_)
        row = [fname, weight, E_qm, E_mm, E_diff, rmsd_]
        writer.writerow(row)
    writer.writerow([])
    writer.writerow(['Weighted Averrage of E_diff',
                     tools.weightedmean(E_diffs, weights)])
    writer.writerow(['Weighted SD of E_diff',
                     tools.weightedsd(E_diffs, weights)])
    writer.writerow(['Weighted Average of RMSD',
                     tools.weightedmean(rmsds, weights)])