Ejemplo n.º 1
0
    def setValue(self, valueKey, values):

        if len(values) == 1 and type(values[0]) == type(''):

            value = values[0]

            if not self.parent.patt['emptyline'].search(value):

                if valueKey == 'num':
                    self.num = returnInt(value)

                elif valueKey == 'assignment':
                    assignment = value.strip()
                    self.assign = assignment.split(self.parent.assignSep)

                elif self.intensity == None and valueKey in ('dataHeight',
                                                             'height'):
                    self.intensity = returnFloat(value)

                elif valueKey == 'fitHeight':
                    self.intensityFit = returnFloat(value)

                elif valueKey == 'intensity':
                    self.intensity = returnFloat(value)

                elif valueKey == 'volume':
                    (volume, volumeMethod) = value.strip().split()
                    self.volume = returnFloat(volume)

                    if volumeMethod == 'ga':
                        self.volumeMethod = 'Gaussian'
                    elif volumeMethod == 'lo':
                        self.volumeMethod = 'Lorentzian'
                    elif volumeMethod == 'bx':
                        self.volumeMethod = 'Sum over box'
                    elif volumeMethod == 'el':
                        self.volumeMethod = 'Sum over ellipse'
                    elif volumeMethod == '--':
                        self.volumeMethod = 'Unknown method'
                    else:
                        self.volumeMethod = 'Unknown method'
                        print "  Error: unknown volume method %s in sparky peaks file (please define)." % volumeMethod

        elif len(values) >= 1:

            if valueKey == 'freqDimsPpm':
                self.ppm = returnFloats(values)

            elif valueKey == 'freqDimsHz':
                self.hz = returnFloats(values)

            elif valueKey == 'freqDimsWidth':
                self.widths = returnFloats(values[:-1])

        else:

            print "  Warning: empty data field for Sparky peak file."
            pass
Ejemplo n.º 2
0
    def checkLinePattern(self, line):

        if string.find(line, 'coefficients') != -1:
            cols = string.split(line)

            self.coeffs = returnFloats(cols[1:])

            return -1

        return 1
Ejemplo n.º 3
0
    def setOtherData(self, weight, peakNum, peakVol, ppms):

        if weight != None:
            self.weight = returnFloat(weight)
        else:
            self.weight = None

        self.peakNum = returnInt(peakNum)
        self.peakVol = returnFloat(peakVol)
        self.ppms = returnFloats(ppms)
Ejemplo n.º 4
0
    def __init__(self,
                 numPoints,
                 numPointsOrig,
                 valuePerPoint,
                 nucleus,
                 phase=None):

        self.numPoints = returnInt(numPoints)
        self.numPointsOrig = returnInt(numPointsOrig)
        self.valuePerPoint = returnFloat(valuePerPoint)
        self.nucleus = nucleus

        if phase:
            self.phase = returnFloats(phase)
        else:
            self.phase = 2 * [0.0]
Ejemplo n.º 5
0
    def __init__(self, num, deleted, ppm, volume, assignResNum, assignRes,
                 assignAtom, ndim, specName):

        self.num = returnInt(num)
        self.deleted = returnInt(deleted)
        self.volume = returnFloat(volume)
        self.specName = (string.strip(specName))[:12]

        self.ppm = returnFloats(ppm)

        self.assignRes = []
        self.assignAtom = []
        self.assignResNum = []

        for i in range(0, ndim):
            self.assignResNum.append(string.strip(assignResNum[i]))
            self.assignRes.append(string.strip(assignRes[i]))
            self.assignAtom.append(string.strip(assignAtom[i]))
Ejemplo n.º 6
0
    def setDataTypes(self):

        self.numPoints = returnInt(self.numPoints)
        self.numPointsOrig = returnInt(self.numPointsOrig)
        self.valuePerPoint = returnFloat(self.valuePerPoint)
        self.phase = returnFloats(self.phase)
Ejemplo n.º 7
0
    def read(self, isOutputFile=False, headerCols=None, verbose=0):

        #
        # TODO TODO also need a 'readFinal' one to read the FINAL information!!
        #           set a flag in MonteFormat.py to select which cs info to read...
        """
    The first column in any data entry is a peak identification number. This is a four
    digit number with one decimal place. The last digit may be incremented, for example,
    to indicated a single parent amide resonance that may give rise to more than one
    carbon or proton cross peaks, i.e. from minor protein conformations or overlapping
    resonance signals.
    
    The second entry is an optional comment of up to eight characters. If there is a
    number in this field, the software will assume that this is a tentative assignment.
    This number is not used in the Monte Carlo protocol; however, is carried over to the
    output files. Using this field to add/change tentative assignment is useful in
    comparing output from multiple Monte runs.
    
    Subsequent entries in each row are chemical shift frequencies and may be separated by
    spaces or comas. The first and second columns must contain the parent amide nitrogen
    and amide proton shifts, in either order (defined by the .par file). The following
    chemical shifts may be in any order, but must be consistent throughout the table. The
    order is user defined in the .par file. (see section on Parameter File)
    
    Any chemical shifts at the very end of the list may be left blank if the shift is
    unknown. However, a unknown chemical shift field positioned within a series of known
    shifts must be entered 0.00 to hold its place (see example peak 101.0 above, no shift
    is identified with the intra residue CA).    
    """

        if verbose == 1:
            print "Reading %s chemical shift list %s" % (self.format,
                                                         self.name)

        fin = open(self.name, 'rU')

        line = fin.readline()

        spinSystemId = 0
        resLabel = oldResLabel = None

        while line:

            if self.patt['%sComment' % self.format].search(line):

                if not isOutputFile and not self.chemShifts and not headerCols:

                    #
                    # Get atom info from first line...
                    #

                    headerCols = line.split()
                    headerCols.pop(0)

                line = fin.readline()
                continue

            if self.patt['emptyline'].search(line):
                line = fin.readline()
                continue

            #
            # Make sure header info is available - otherwise no point
            #

            if not headerCols:
                raise "Error: no header column information available. Try reading .par file!"
                return

            #
            # Get the info... should really come for .par file!!
            #

            cols = line.split()

            infoCode = None

            if not isOutputFile:

                stripId = returnFloat(cols.pop(0))

                #
                # NOt necessarily info string available...
                #

                if self.patt['onlyFloat'].search(cols[0]):
                    seqCode = None
                    resLabel = None

                else:
                    assignment = cols.pop(0)

                    searchAssignment = self.patt[
                        '%sAssignment' % self.format].search(assignment)

                    resLabel = searchAssignment.group(1)
                    seqCode = searchAssignment.group(2)

            else:

                seqCode = cols.pop(0)
                if seqCode[-1] in '+':
                    seqCode = seqCode[:-1]
                    infoCode = seqCode[-1]

                oldResLabel = resLabel
                resLabel = cols.pop(0)
                stripId = returnFloat(cols.pop(0))
                voidCol = cols.pop(0)

            #
            # Set up info for atoms...
            #

            if not seqCode or seqCode == '?':
                seqCode = None
                spinSystemId = spinSystemId + 2
            else:
                seqCode = returnInt(seqCode)

            if len(cols) == 1:
                cols = cols.split(',')

            values = returnFloats(cols)

            for i in range(0, len(values)):
                atomId = headerCols[i]
                value = values[i]

                if value == 0.0:
                    continue

                atomSearch = self.patt['%sAtomInfo' %
                                       self.format].search(atomId)

                atomName = atomSearch.group(1)
                atomPlace = atomSearch.group(2)

                if atomName == 'HA1':
                    nextAtomValue = values[i + 1]
                    if nextAtomValue == 0.00:
                        atomName = 'HA'

                curSeqCode = seqCode
                curResLabel = None

                if seqCode == None:
                    curSpinSystemId = spinSystemId
                    prevSpinSystemId = spinSystemId - 1
                else:
                    curSpinSystemId = None
                    prevSpinSystemId = None

                if atomPlace == '(i-1)' or atomPlace == '-1':

                    if seqCode != None:
                        curSeqCode = seqCode - 1
                    else:
                        curSpinSystemId = spinSystemId - 1
                        prevSpinSystemId = None

                    if not isOutputFile:
                        curResLabel = resLabel
                    else:
                        curResLabel = oldResLabel

                elif isOutputFile:
                    curResLabel = resLabel

                self.chemShifts.append(
                    MonteChemShift(value,
                                   atomName,
                                   curSeqCode,
                                   curSpinSystemId,
                                   stripId,
                                   curResLabel,
                                   self.defaultMolCode,
                                   infoCode=infoCode,
                                   prevSpinSystemId=prevSpinSystemId))

            line = fin.readline()

        fin.close()
Ejemplo n.º 8
0
    def read(self, verbose=0, expname='unknown'):

        if verbose == 1:

            print "Reading Varian acquisition parameters file %s" % self.name

        # For reading: Varian parameter stored format is made up of 3 OR MORE lines!
        # See VarianPar class definition for more detailed info.

        fin = open(self.name, 'rU')
        line = fin.readline()

        while line:
            # Checking of empty lines and hashes not really necessary, but left in just in case
            if not (self.patt['emptyline'].search(line)
                    or self.patt['hash'].search(line)):
                cols = line.split()
                if len(cols) != 11:
                    print "  ERROR: %s Varian procpar has wrong number of fields on following line:" % expname + self.newline + line
                elif self.parameters.has_key(cols[0]):
                    print("Reoccuring parameter name: %s" %
                          cols[0]) + self.newline
                else:
                    parname = cols[0]
                    self.parameters[parname] = VarianAcqPar(
                        parname, cols[1], cols[2], cols[3], cols[4], cols[5],
                        cols[6], cols[7], cols[8], cols[9])
                    self.parameters[parname].addHelp(self.parHelp, verbose)

                    # Read values (LINE 2)
                    line = fin.readline()
                    cols = line.split()
                    value_len = returnInt(cols[0])

                    if self.parameters[parname].basictype == 1:
                        # Case real data type
                        self.parameters[parname].addvalues(
                            expname, value_len, returnFloats(cols[1:]))
                    elif self.parameters[parname].basictype == 2:
                        # Case string data type
                        values = []
                        values.append(joinUnquote(cols[1:], '"'))

                        # For multiple line string data, read other lines
                        for value_num in range(1, value_len):
                            # Read values
                            line = fin.readline()
                            cols = line.split()
                            values.append(joinUnquote(cols, '"'))

                        self.parameters[parname].addvalues(
                            expname, value_len, values)

                    else:
                        # Case undefined data type
                        print "  ERROR: %s Varian procpar has undefined basic data type. Check parameter %s." % (
                            expname, parname)

                    # Read enumerations (LAST LINE)
                    line = fin.readline()
                    cols = line.split()
                    enum_len = returnInt(cols[0])

                    if enum_len == 0:
                        self.parameters[parname].addenum(expname, enum_len, '')
                    else:
                        self.parameters[parname].addenum(
                            expname, enum_len, unquote(cols[1:], '"'))

            line = fin.readline()
Ejemplo n.º 9
0
    def read(self, verbose=False, maxNum=999, ignoreResNames=None):
        """
MD of 2 waters, t= 0.0
    6
    1WATER  OW1    1   0.126   1.624   1.679  0.1227 -0.0580  0.0434
    1WATER  HW2    2   0.190   1.661   1.747  0.8085  0.3191 -0.7791
    1WATER  HW3    3   0.177   1.568   1.613 -0.9045 -2.6469  1.3180
    2WATER  OW1    4   1.275   0.053   0.622  0.2519  0.3140 -0.1734
    2WATER  HW2    5   1.337   0.002   0.680 -1.0641 -1.1349  0.0257
    2WATER  HW3    6   1.326   0.120   0.568  1.9427 -0.8216 -0.0244
   1.82060   1.82060   1.82060

Lines contain the following information (top to bottom):

    title string (free format string, optional time in ps after 't=')
    number of atoms (free format integer)
    one line for each atom (fixed format, see below)
    box vectors (free format, space separated reals), values: v1(x) v2(y) v3(z) v1(y) v1(z) v2(x) v2(z) v3(x) v3(y), the last 6 values may be omitted (they will be set to zero). Gromacs only supports boxes with v1(y)=v1(z)=v2(z)=0. 

This format is fixed, ie. all columns are in a fixed position. Optionally (for now only yet with trjconv) you can write gro files with any number of decimal places, the format will then be n+5 positions with n decimal places (n+1 for velocities) in stead of 8 with 3 (with 4 for velocities). Upon reading, the precision will be inferred from the distance between the decimal points (which will be n+5). Columns contain the following information (from left to right):

    residue number (5 positions, integer)
    residue name (5 characters)
    atom name (5 characters)
    atom number (5 positions, integer)
    position (in nm, x y z in 3 columns, each 8 positions with 3 decimal places)
    velocity (in nm/ps (or km/s), x y z in 3 columns, each 8 positions with 4 decimal places) 

Note that separate molecules or ions (e.g. water or Cl-) are regarded as residues. If you want to write such a file in your own program without using the GROMACS libraries you can use the following formats:

C format
    "%5d%5s%5s%5d%8.3f%8.3f%8.3f%8.4f%8.4f%8.4f" 
Fortran format
    (i5,2a5,i5,3f8.3,3f8.4) 
    """

        if verbose:
            print "Reading %s coordinate file %s" % (self.format, self.name)

        if not ignoreResNames:
            ignoreResNames = ('SOL', )

        #
        # Read coordinates and other info
        #

        currentChainCode = None
        oldResNum = None

        fin = open(self.name, 'rU')
        lines = fin.readlines()
        fin.close()

        self.title = lines[0]
        self.numAtoms = returnInt(lines[1])
        self.boxCoords = returnFloats(lines[-1].split())

        modelNum = 1
        self.modelCoordinates[modelNum] = []

        for line in lines[2:-1]:

            resNum = returnInt(line[:5])
            resName = line[5:10].strip()
            atomName = line[10:15].strip()
            atomSerial = returnInt(line[15:20])

            # Don't read solvent by default, can be changed...
            if resName in ignoreResNames:
                continue

            coordAndVelocities = line[20:].split()

            (x, y, z) = returnFloats(coordAndVelocities[:3])

            if len(coordAndVelocities) > 3:
                velocities = returnFloats(coordAndVelocities[3:])
            else:
                velocities = []

            # Initialise this at start of file reading
            if currentChainCode == None:
                currentChainCode = self.chainCodes[0]
                oldResNum = resNum
                self.chains.append(GromosChain(currentChainCode))

            # New chain code if residue number jump
            if resNum < oldResNum or oldResNum + 1 < resNum:
                currentChainCode = self.chainCodes[
                    self.chainCodes.index(currentChainCode) + 1]
                oldResNum = resNum
                self.chains.append(GromosChain(currentChainCode))

            self.modelCoordinates[modelNum].append(
                GromosCoordinate(atomSerial,
                                 atomName,
                                 resName,
                                 currentChainCode,
                                 resNum,
                                 x,
                                 y,
                                 z,
                                 velocities=velocities))

            oldResNum = resNum

        fin.close()
Ejemplo n.º 10
0
    def read(self, verbose=0):

        if verbose == 1:
            print "Reading Bruker acquisition parameters file %s" % self.name

        # For reading: based on ##
        # If value between <> or non-numeric characters (except point): is string
        # If value numeric: float if contains '.'
        #                   integer if no '.'
        #                   (data type doesn't matter for python comparisons (5 == 5.0))

        fin = open(self.name, 'rU')
        line = fin.readline()

        while line:

            #
            # Checking of empty lines not really necessary, but left in just in case
            #

            if not (self.patt['emptyline'].search(line)):

                cols = line.split()

                if self.patt[self.format + 'StartDoubleHashDollar'].search(
                        cols[0]):

                    #
                    # This is a variable
                    #

                    parname = self.patt[self.format +
                                        'StartDoubleHashDollar'].sub(
                                            '', cols[0])
                    parname = parname.replace('=', '')

                    self.parameters[parname] = BrukerPar(parname)
                    #self.parameters[parname].addHelp(self.parHelp,verbose)

                    # Handle value(s): is or are always in list
                    valuestring = ' '.join(cols[1:])
                    values = []
                    valueCount = 1

                    # Is an array? Indicated by (n..m) search above
                    if self.patt[self.format +
                                 'BracketsListIndicator'].search(valuestring):

                        # Values can start IMMEDIATELY after right bracket! Split accordingly
                        if self.patt[self.format +
                                     'BracketCloseNumber'].search(valuestring):
                            (listinfo, line) = valuestring.split(')')
                        else:
                            listinfo = valuestring
                            line = ''

                        # For info on list, get rid of brackets and split on '..', find value_len
                        listinfo = self.patt['bracketEither'].sub('', listinfo)
                        (listStart, listEnd) = returnInts(listinfo.split('..'))
                        valueLen = listEnd - listStart + 1

                        # Report error if valueMin not zero!!
                        if listStart != 0:
                            print "Error: Bruker array starts at non-zero for %s!" % parname

                        # Start parsing list values here. If they were behind the right bracket,
                        # the string containing them is the current line.
                        # LISTS LIKE THIS ARE ALWAYS CONSIDERED FLOAT DATE TYPE!
                        valueType = 'float'
                        valueCount = 0

                        while 1 == 1:
                            # Always check if this line doesn't have '##'
                            if self.patt[self.format +
                                         'StartDoubleHash'].search(line):
                                print "Parsing error:%s" % line + self.newline
                            cols = line.split()
                            values.extend(returnFloats(cols))
                            valueCount += len(cols)
                            if valueCount < valueLen:
                                line = fin.readline()
                            else:
                                break

                    # Is a text value (between <>)? If so, need to find matching '>',
                    # since this can be multi-line.
                    elif self.patt[self.format +
                                   'SharpBracketOpen'].search(valuestring):
                        while not self.patt[self.format +
                                            'SharpBracketClose'].search(
                                                valuestring):
                            line = fin.readline()
                            # Always check if this line doesn't have '##'
                            if self.patt[self.format +
                                         'StartDoubleHash'].search(line):
                                print "Parsing error:%s" % line
                            line = line.rstrip()
                            valuestring += line
                        valuestring = self.patt[self.format +
                                                'SharpBracketEither'].sub(
                                                    '', valuestring)
                        values.append(self.patt[self.format +
                                                'FinalReturn'].sub(
                                                    '', valuestring))
                        valueType = 'string'

                    # Is a number
                    elif self.patt[self.format +
                                   'DigitDotDigit'].search(valuestring):
                        # Is a float
                        if self.patt[self.format + 'Dot'].search(valuestring):
                            valueType = 'float'
                            values.append(returnFloat(valuestring))
                        # Is an integer
                        else:
                            valueType = 'int'
                            values.append(returnInt(valuestring))

                    # Is a string (unquoted)
                    else:
                        valueType = 'string'
                        values.append(valuestring)

                    # Add value to parameter
                    self.parameters[parname].addValues(valueCount, values)
                    self.parameters[parname].addType(valueType)
                    self.parameters[parname].addHelp(self.parHelp, verbose)

                elif self.patt[self.format + 'StartDoubleDollar'].search(
                        cols[0]):
                    # This is a date line or the original file name with path
                    self.infoStrings.append(line[3:].strip())
                elif self.patt[self.format + 'StartDoubleHash'].search(
                        cols[0]):
                    # General information about parameter file
                    pass
                else:
                    print "Error: undefined basic data line:%s" % line + self.newline

            line = fin.readline()