Esempio n. 1
0
def splitInput(filename):
    """
        Split the parallel input file into multiple async file names

        Parameters
            filename:  The path to the original parallel input
                       file (string)
    """
    nproc = 0
    file = open(filename)
    text = ""
    while 1:
        line = file.readline()
        if line == "": break
        text += line
        line = string.strip(line)
        if line.startswith("pdime"): # Get # Procs
            words = string.split(line)
            nproc = int(words[1]) * int(words[2]) * int(words[3])

    if nproc == 0:
        sys.stderr.write("%s is not a valid APBS parallel input file!\n" % filename)
        sys.stderr.write("The inputgen script was unable to asynchronize this file!\n")
        sys.exit(2)

    period = string.find(filename,".")
    for i in range(nproc):
        outname = filename[0:period] + "-PE%i.in" % i
        outtext = string.replace(text, "mg-para\n","mg-para\n    async %i\n" % i)
        outfile = open(outname, "w")
        outfile.write(outtext)
        outfile.close()
Esempio n. 2
0
 def parseLines(self, lines):
     """ Parse the lines """
     for line in lines:
         if string.find(line, "ATOM") == 0:
             subline = string.replace(line[30:], "-", " -")
             words = string.split(subline)
             if len(words) < 4:
                 #sys.stderr.write("Can't parse following line:\n")
                 #sys.stderr.write("%s\n" % line)
                 #sys.exit(2)
                 continue
             self.gotatom = self.gotatom + 1
             self.q = self.q + float(words[3])
             rad = float(words[4])
             center = []
             for word in words[0:3]:
                 center.append(float(word))
             for i in range(3):
                 self.minlen[i] = min(center[i] - rad, self.minlen[i])
                 self.maxlen[i] = max(center[i] + rad, self.maxlen[i])
         elif string.find(line, "HETATM") == 0:
             self.gothet = self.gothet + 1
Esempio n. 3
0
def setID(time):
    """
        Given a floating point time.time(), generate an ID.
        Use the tenths of a second to differentiate.

        Parameters
            time:  The current time.time() (float)
        Returns
            id  :  The file id (string)
    """
    strID = "%s" % time
    period = string.find(strID, ".")
    id = "%s%s" % (strID[:period], strID[(period+1):(period+2)])
    return id
 def formatName(self, at):
     altLoc = None
     name = at.name
     #if len(name)>2 and name[-2]=='@':
     if string.find(name, '@') > -1:
         ind = string.index(name, '@')
         altLoc = name[ind + 1:]
         #altLoc = name[-1]
         name = name[:ind]
     if len(name) == 4:
         if at.element == 'H':
             name = name[-1] + name[:-1]
             nameStr = '%-4.4s' % name
         else:
             nameStr = '%4.4s' % name
     elif len(at.element) == 2:
         nameStr = '%-4.4s' % at.element
     else:
         nameStr = ' %-3s' % name
     return nameStr, altLoc
Esempio n. 5
0
def cleanTmpdir():
    """
        Clean up the temp directory for CGI.  If the size of the directory
        is greater than LIMIT, delete the older half of the files.  Since
        the files are stored by system time of creation, this is an
        easier task.
    """
    newdir = []
    size = 0.0
    count = 0
    path = LOCALPATH + TMPDIR

    dir = os.listdir(path)
    for filename in dir:
        size = size + os.path.getsize("%s%s" % (path, filename))
        period = string.find(filename,".")
        id = filename[:period]
        if id not in newdir:
            newdir.append(id)
            count += 1

    newdir.sort()
    size = size / (1024.0 * 1024.0)

    newcount = 0
    if size >= LIMIT:
        for filename in newdir:
            if newcount > count/2.0: break
            try:
                os.remove("%s%s.pqr" % (path, filename))
            except OSError: pass
            try:
                os.remove("%s%s.in" % (path, filename))
            except OSError: pass
            try:
                os.remove("%s%s.html" % (path, filename))
            except OSError: pass
            newcount += 1
Esempio n. 6
0
    def printInputFiles(self):
        """
            Make the input file(s) associated with this object
        """
        period = string.find(self.pqrpath,".")
        if self.asyncflag == 1:
            outname = self.pqrpath[0:period] + "-para.in"

            # Temporarily disable async flag
            for elec in self.elecs:
                elec.asyncflag = 0
            file = open(outname, "w")
            file.write(str(self))
            file.close()

            # Now make the async files
            elec = self.elecs[0]

            nproc = elec.pdime[0] * elec.pdime[1] * elec.pdime[2]
            for i in range(int(nproc)):
                outname = self.pqrpath[0:period] + "-PE%i.in" % i
                for elec in self.elecs:
                    elec.asyncflag = 1
                    elec.async = i
                file = open(outname, "w")
                file.write(str(self))
                file.close()

        else:
            if period > 0:
                outname = self.pqrpath[0:period] + ".in"
            else:
                outname = self.pqrpath + ".in"
            file = open(outname, "w")
            file.write(str(self))
            file.close()
Esempio n. 7
0
def getTestSummaryResults(testroot, testreportdir):
    """Parse the test report files created by tester.
    testroot - directory containing the MGLTools packages ;
    testreportdir - directory containing testreports """
    #print "testreportdir:", testreportdir
    assert os.path.exists(testreportdir)
    assert os.path.exists(testroot)
    # list of directories containing Tests ( created when the tests ran last for this platform)

    cwd = os.getcwd()

    testdirs = []
    os.chdir(testroot)
    for p in mglpacks:
        os.path.walk(p, getTestsDirs, testdirs)
    #print  "testdirs" ,testdirs
    os.chdir(cwd)
    reports = []
    for p in testdirs:
        reports.append(p.replace(os.sep, '.'))

    # a dictionary containing the names of test reports
    rantests = {}
    # a dictionary containing the names of test reports (with -s option)
    rantestsS = {}
    # a list of test modules for which we did not get a report
    noreports = []

    modules = []
    # string containing time when the directory was last modified
    reporttime = time.asctime(
        time.localtime(os.stat(testreportdir)[stat.ST_MTIME]))

    # remove time (##:##:##)   from reporttime string (leave only the date)
    rd = string.split(reporttime)
    rd.pop(-2)
    reportdate = "%s %s %s %s" % tuple(rd)

    import sys
    for r in reports:
        f1 = os.path.join(testroot, testreportdir,
                          "report-" + r + sys.platform + ".txt")
        f2 = os.path.join(testroot, testreportdir,
                          "sReport-" + r + sys.platform + ".txt")

        if os.path.exists(f1):
            rantests[f1] = r
        elif os.path.exists(f2):
            rantestsS[f2] = r
        else:
            noreports.append(r)

    numtests = 0
    numerrors = 0
    results = {}
    for file in list(rantestsS.keys()):
        test = None
        ntests = 0
        testerrors = 0
        f = open(file, "r")
        st = f.readline()
        l = string.split(st)
        if len(l) == 5:
            if l[0] == "RAN":
                test = rantestsS[file]
                ntests = float(l[1])
                numtests = numtests + ntests
                modules.append(test)
                results[test] = {}
                results[test]['ntests'] = ntests
        txt = f.readlines()
        f.close()
        testname = None
        errlist = []
        errtxt = ""
        for line in txt:
            if string.find(line, "Tests.test_") > 0:
                if string.find(line, "ERROR:") == 0 or string.find(
                        line, "FAIL:") == 0:
                    errlist.append(line)
                    continue
                testname = line
                if len(errlist) > 0:
                    errtxt = errtxt + "\n" + testname
                    for err in errlist:
                        errtxt = errtxt + err
                    testerrors = testerrors + len(errlist)
                    errlist = []

                continue
            elif string.find(line, "ERROR:") == 0 or string.find(
                    line, "FAIL:") == 0:
                errlist.append(line)
            elif line.startswith("RAN "):
                if test == None:
                    test = rantestsS[file]
                    modules.append(test)
                    results[test] = {}
                #print test, file, ntests, numtests,
                nt = float(line.split()[1])
                ntests = ntests + nt
                numtests = numtests + nt
                #print ntests, numtests
                results[test]['ntests'] = ntests

        #this is for the case when error is in the last test:
        if len(errlist) > 0:
            errtxt = errtxt + "\n" + testname
            for err in errlist:
                errtxt = errtxt + err
            testerrors = testerrors + len(errlist)
            errlist = []

        if testerrors:
            numerrors = numerrors + testerrors
            results[test]['failed'] = testerrors
            results[test]['errtxt'] = errtxt

    for file in list(rantests.keys()):
        testerrors = 0
        f = open(file, "r")
        st = f.readline()
        l = string.split(st)
        if len(l) == 5:
            if l[0] == "RAN":
                test = rantests[file]
                modules.append(test)
                ntests = float(l[1])
                numtests = numtests + ntests
                results[test] = {}
                results[test]['ntests'] = ntests

        txt = f.readlines()
        f.close()
        testname = None
        errlist = []
        errtxt = ""
        for line in txt:
            if string.find(line, "FAILED (") == 0:
                if len(errlist) > 0:
                    for err in errlist:
                        errtxt = errtxt + err
                    testerrors = testerrors + len(errlist)
                    errlist = []
                continue
            elif string.find(line, "ERROR:") == 0 or string.find(
                    line, "FAIL:") == 0:
                errlist.append(line)
        if testerrors:
            numerrors = numerrors + testerrors
            results[test]['failed'] = testerrors
            results[test]['errtxt'] = errtxt

    perc = numerrors / numtests * 100.0
    if len(noreports):
        endstr = "No test report for the following module(s) (tests possibly crashed): \n"
        for f in noreports:
            endstr = endstr + "%s \n" % f
        results['tail'] = endstr
    results['reportdate'] = reportdate
    results['numtests'] = numtests
    results['numerrors'] = numerrors
    results['perc'] = perc

    return results, modules
    def read(self, filename):
        """
1.5 2.0 binding
  0   0   0   0  0.000  0.000  0.000 -14.645
  1   0   1   0  2.449  0.000  0.000 -14.636
  0   1   0   1  1.281  1.281  1.281 -14.424
  1   1   1   1  2.548  1.014  1.014 -14.210
                   |      |      |
                   |      |      |-rmsd from cluster seed @ 2.0 tolerance
                   |      |-rmsd from cluster seed @ 1.0 tolerance
                   |-rmsd from overall reference structure
        """
        file_ptr = open(filename)
        lines = file_ptr.readlines() # read the file
        file_ptr.close()

        d = self.clustering_dict # local copy

        # see if there's the last char is a 'd' or 'b'  or 'e'to denote energy
        word_list = string.split(lines[0])
        if word_list[-1][0] in ['b', 'd', 'e']:
            file_energy_used = word_list[-1]
            ind = string.find(lines[0], file_energy_used)
            lines[0] = lines[0][:ind] # strip energy symbol
        else:
            file_energy_used = 'binding'

        # ??? make sure we're consistent with the argsort
        #check that self has done some clustering before this
        if len(self.clustering_dict)>0:
            assert file_energy_used[0] == self.energy_used[0], 'Cluster energy mismatch'
        else:
            #here the dlg had no clustering in it
            self.energy_used = file_energy_used
            #redo argsort with file_energy_used
            if file_energy_used[0] == 'd':
                energy_list = [conf.docking_energy for conf in self.data]
            else:
                energy_list = [conf.binding_energy for conf in self.data]
            # sort the conformations by energy
            self.argsort = numpy.argsort(energy_list)
            #print "self.argsort=", self.argsort

        t_list = list(map(float, string.split(lines[0])))
        #t_list for the example is [0.5, 2.0]
        num_t = len(t_list)   #number of clusterings

        for tolerance in t_list: # initialize the keys
            if tolerance in d:
                raise RuntimeError("overwriting existing clustering")
            c = d[tolerance] = Clustering()
            c.tolerance = tolerance

        # cx is the index into self.data, the list of conformatons
        # NEW FORMAT:
        # 0   0   0   0  0.000  0.000  0.000 -14.645
        #first line has list of tolerances
        for cx, l in enumerate(lines[1:]):
            ll = l.split()
            #eg: 2 tolerances gives [ 0,  0,  0,  0, 0.000, 0.000, 0.000,-14.645]
            #num_t *2
            c_list = list(map(int, ll[:num_t*2]))
            data_list = list(map(float, ll[num_t*2:]))

            for t, i in zip(t_list, range(len(c_list)/2)):
                cluster_index = c_list[2*i]
                cluster_rank = c_list[2*i+1]
                conf = self.data[int(self.argsort[cx])]
                if cluster_rank == 0:
                    assert len(d[t]) == cluster_index
                    d[t].append(Cluster(conf))
                else:
                    # add conformation to its cluster
                    assert len(d[t][cluster_index]) == cluster_rank
                    d[t][cluster_index].append(conf)
                # tell the conformation what cluster(s) it belongs to...
                conf.cluster_dict[t] = (cluster_index, cluster_rank)
                conf.refRMS = data_list[0]
                conf.clRMS = data_list[1]