예제 #1
0
 def setRdcData(self,value,error=0.00, energyCst=1.0, orientation=0):
 
   self.error = returnFloat(error)
   self.value = returnFloat(value)
   self.energyCst = returnFloat(energyCst)
   
   self.orientation = returnInt(orientation)
예제 #2
0
    def __init__(self,
                 parent,
                 serial,
                 atomName,
                 resName,
                 chainId,
                 seqCode,
                 x,
                 y,
                 z,
                 segId,
                 insertionCode=defaultSeqInsertCode):

        self.parent = parent
        self.serial = returnInt(serial)
        self.atomName = string.strip(atomName)
        self.resName = string.strip(resName)
        self.chainId = chainId
        self.seqCode = returnInt(seqCode)
        self.x = returnFloat(x)
        self.y = returnFloat(y)
        self.z = returnFloat(z)
        self.segId = string.strip(segId)
        self.insertionCode = insertionCode

        if not self.segId:
            self.segId = self.chainId
예제 #3
0
    def setSpectrum(self, specName, ppm):

        specName = string.strip(specName)

        # If spectrum name already exists, see if number of dims matches
        if self.specNames.count(specName) == 1:
            specNameIndex = self.specNames.index(specName)
            numDim = self.numDims[specNameIndex]

            # Just to make sure not fluke peak with ppm 0.00000 as first one
            # for a particular spectrum, check again
            # TODO: this slows things down... should only do this ten times or so

            ndim = self.maxDim

            for ppmVal in ppm:
                if returnFloat(ppmVal) == 0.0:
                    ndim -= 1

            if ndim > numDim:
                self.numDims[specNameIndex] = None

        # If doesn't exist, create
        else:
            self.specNames.append(specName)

            ndim = self.maxDim

            for ppmVal in ppm:
                if returnFloat(ppmVal) == 0.0:
                    ndim -= 1

            self.numDims.append(ndim)
예제 #4
0
    def __init__(self,
                 serial,
                 atomName,
                 resName,
                 segId,
                 seqCode,
                 x,
                 y,
                 z,
                 insertionCode=defaultSeqInsertCode,
                 altLoc=defaultAltLoc,
                 chainId=None):

        self.serial = returnInt(serial)
        self.atomName = atomName.strip()
        self.resName = resName.strip()
        self.seqCode = returnInt(seqCode)
        self.x = returnFloat(x)
        self.y = returnFloat(y)
        self.z = returnFloat(z)
        self.insertionCode = insertionCode
        self.altLoc = altLoc

        self.segId = segId.strip()

        if chainId == None:
            self.chainId = self.segId
            if not self.chainId:
                self.chainId = defaultMolCode
        else:
            self.chainId = chainId
예제 #5
0
    def __init__(self,
                 num,
                 ppm,
                 colour,
                 userCode,
                 volume,
                 volumeError,
                 intCode,
                 assign,
                 verbose=False,
                 comment=None,
                 textAssign=False):

        self.num = returnInt(num, default=None, verbose=verbose)
        self.volume = returnFloat(volume, default=None, verbose=verbose)
        self.volumeError = returnFloat(volumeError,
                                       default=None,
                                       verbose=verbose)
        self.colour = returnInt(colour, default=None, verbose=verbose)
        self.userCode = userCode
        self.intCode = intCode

        self.comment = comment
        self.textAssign = textAssign

        self.ppm = []
        self.assign = []
        self.ambiguousAssign = []

        for i in range(len(assign)):
            self.ppm.append(returnFloat(ppm[i], default=None, verbose=verbose))

            self.assign.append(self.getAssignmentValue(assign[i]))
예제 #6
0
    def __init__(self,
                 serial,
                 atomName,
                 seqCode,
                 resName,
                 chainId,
                 x,
                 y,
                 z,
                 insertionCode=defaultSeqInsertCode,
                 refChainId=None,
                 verbose=False):

        self.serial = returnInt(serial, verbose=verbose)
        self.atomName = atomName.strip()
        self.seqCode = returnInt(seqCode, verbose=verbose)
        self.resName = resName.strip()
        self.chainId = chainId
        self.x = returnFloat(x, default=None, verbose=verbose)
        self.y = returnFloat(y, default=None, verbose=verbose)
        self.z = returnFloat(z, default=None, verbose=verbose)
        self.segId = ''
        self.insertionCode = insertionCode

        if refChainId:
            self.refChainId = refChainId
        else:
            self.refChainId = chainId
예제 #7
0
def readCloudFile(fileName, hydrogenOnly=True):

    file = open(fileName, 'r')
    coords = []
    atoms = []
    shifts = []
    serials = []

    for line in file.readlines():
        key = line[0:6].strip()
        if key == 'ATOM':
            a = line[13:16].strip()
            x = returnFloat(line[30:38])
            y = returnFloat(line[38:46])
            z = returnFloat(line[46:54])
            n = int(float(line[54:60].strip() or 0.0) * 100)
            s = float(line[60:66].strip() or 0.0) / 10.0

            if hydrogenOnly:
                if (a[0] == 'H') or (a == 'CH3'):
                    coords.append([x, y, z])
                    shifts.append(s)
                    atoms.append(a)
                    serials.append(n)
            else:
                coords.append([x, y, z])
                shifts.append(s)
                atoms.append(a)
                serials.append(n)

    return (coords, serials, shifts, atoms)
예제 #8
0
 def __init__(self,parent,atomSerial,value,valueError,atomName,seqCode,verbose=False):
 
   self.atomSerial = returnInt(atomSerial,default=None,verbose=verbose)
   self.value = returnFloat(value,default=None,verbose=verbose)
   self.valueError = returnFloat(valueError,default=None,verbose=verbose)
   self.atomName = atomName
   (self.seqCode,self.seqInsertCode) = getSeqAndInsertCode(seqCode)
   self.molCode = parent.defaultMolCode
예제 #9
0
파일: peaksIO.py 프로젝트: fenglb/ccpnmr2.4
    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
예제 #10
0
    def __init__(self, parent, atomSerial, x, y, z, atomType, massDiff, charge,
                 Hcount, stereoCare, valence):

        self.parent = parent
        self.parent.numAtoms -= 1

        self.serial = atomSerial

        self.x = returnFloat(x, verbose=0)
        self.y = returnFloat(y, verbose=0)
        self.z = returnFloat(z, verbose=0)
        """
    entry in periodic table or L for atom list, 
    A, Q, * for unspecified atom, and LP for 
    lone pair, or R# for Rgroup label
    """

        atomType = string.strip(atomType)

        if atomType in ['A', 'Q', '*']:
            atomType = None
        elif atomType == 'LP':
            atomType = None
            #atomType = 'lone pair' TODO TODO can't handle this yet

        self.atomType = atomType
        """
    -3, -2, -1, 0, 1, 2, 3, 4 
    (0 if value beyond these limits)
    """

        self.massDiff = returnInt(massDiff, verbose=0)
        """
    0 = uncharged or value other than these,
    1 = +3, 2 = +2, 3 = +1,  
    4 = doublet radical, 5 = -1, 6 = -2, 7 = -3
    """

        chargeCode = returnInt(charge, verbose=0)
        self.charge = [0, 3, 2, 1, 'dr', -1, -2, -3][chargeCode]
        """
    1 = H0, 2 = H1, 3 = H2, 4 = H3, 5 = H4
    """
        self.Hcount = returnInt(Hcount, verbose=0) - 1
        """
    0 = ignore stereo configuration of this 
    double bond atom, 1 = stereo 
    configuration of double bond atom 
    must match        
    """
        self.stereoCare = returnInt(stereoCare, verbose=0)
        """
    0 = no marking (default) 
    (1 to 14) = (1 to 14) 15 = zero valence
    """
        self.valence = returnInt(valence, verbose=0)
예제 #11
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)
예제 #12
0
    def __init__(self, num, ppm, intensity, verbose=False):

        self.num = returnInt(num, default=None, verbose=verbose)
        self.intensity = returnFloat(intensity, default=None, verbose=verbose)

        self.assign = []
        self.ppm = []

        for i in range(0, len(ppm)):
            self.ppm.append(returnFloat(ppm[i], default=None, verbose=verbose))
            self.assign.append(None)
예제 #13
0
    def __init__(self, Id, intensity, assign, ppm, dimSlice=[]):

        self.num = returnInt(Id)
        self.intensity = returnFloat(intensity)
        self.assign = assign[:]
        self.dimSlice = dimSlice[:]

        self.ppm = []

        for i in range(0, len(ppm)):
            self.ppm.append(returnFloat(ppm[i]))
예제 #14
0
    def __init__(self, num, assign, ppm, intensity, status):

        self.num = returnInt(num)
        self.intensity = returnFloat(intensity)
        self.status = status

        self.assign = []
        self.ppm = []

        for i in range(0, len(assign)):
            self.ppm.append(returnFloat(ppm[i]))
            self.assign.append(assign[i])
예제 #15
0
  def __init__(self,serial,chainId,atomName,resName,seqCode,x,y,z, insertionCode = defaultSeqInsertCode):
  
    self.serial = returnInt(serial)
    self.atomName = atomName.strip()
    self.resName = resName.strip()
    self.seqCode = returnInt(seqCode)

    self.x = returnFloat(x)
    self.y = returnFloat(y)
    self.z = returnFloat(z)
    self.insertionCode = insertionCode

    self.chainId = chainId
예제 #16
0
    def setAngleData(self,
                     lowerAngle,
                     upperAngle,
                     energyCst=1.0,
                     verbose=False):

        self.lowerAngle = returnFloat(lowerAngle,
                                      default=None,
                                      verbose=verbose)
        self.upperAngle = returnFloat(upperAngle,
                                      default=None,
                                      verbose=verbose)
        self.energyCst = returnFloat(energyCst, verbose=verbose)
예제 #17
0
 def setRdcData(self,value,error,weight):
 
   self.value = returnFloat(value)
   
   if error == None:
     self.error = 1.0
   else:     
     self.error = returnFloat(error)
   
   if weight == None:
     self.weight = 1.0
   else:
     self.weight = returnFloat(weight)
예제 #18
0
  def __init__(self,serial,atomName,resName,segId,seqCode,segSeqCode,x,y,z, insertionCode = defaultSeqInsertCode,verbose=False):
  
    self.serial = returnInt(serial,verbose=verbose)
    self.atomName = string.strip(atomName)
    self.resName = string.strip(resName)
    self.seqCode = returnInt(seqCode,verbose=verbose)
    self.segSeqCode = returnInt(segSeqCode,verbose=verbose)
    self.x = returnFloat(x,default=None,verbose=verbose)
    self.y = returnFloat(y,default=None,verbose=verbose)
    self.z = returnFloat(z,default=None,verbose=verbose)
    self.insertionCode = insertionCode

    self.chainId = self.segId = string.strip(segId)
    if not self.chainId:
      self.chainId = defaultMolCode
예제 #19
0
    def read(self, isOutputFile=False, headerCols=None, verbose=0):

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

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

        headerCols = []

        line = fin.readline()

        while line:

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

                line = fin.readline()
                continue

            #
            # Get the info...
            #

            cols = line.split()

            if cols[0].count('NUM'):
                headerCols = line.split()
                colLen = len(headerCols)

            elif len(cols) == colLen and not cols[0].count("-"):

                badShifts = False

                # These are fishy shifts, need to remove the *!
                if cols[0][0] == '*':
                    cols[0] = cols[0][1:]
                    badShifts = True

                seqCode = returnInt(cols[0], default=None, verbose=False)
                resLabel = cols[1]

                if seqCode != None:
                    self.seqCodeLabels[seqCode] = resLabel

                    for i in range(2, colLen):
                        atomName = headerCols[i]
                        value = returnFloat(cols[i],
                                            default=None,
                                            verbose=False)

                        # Ignore if value is 0.00. This is stupid but has to be done because format is set up this way.
                        if value != 0.00:

                            self.chemShifts.append(
                                self.shiftClass(self, value, atomName, seqCode,
                                                resLabel, self.defaultMolCode))

            line = fin.readline()

        fin.close()
예제 #20
0
def setOriginalData(format,parent,rawData,name,isUnique = True):

  #
  # Code to set original data in the data model as application data
  #

  if hasattr(rawData,name):

    keyword = 'orig' + name[0].upper() + name[1:]
    value = getattr(rawData,name)
    appDataClass = None
    
    if value != None:

      if type(returnInt(value,default=None,verbose=0)) == type(value):
        appDataClass = 'AppDataInt'
      elif type(returnFloat(value,default=None,verbose=0)) == type(value):
        appDataClass = 'AppDataFloat'
      elif type(returnLong(value,default=None,verbose=0)) == type(value):
        appDataClass = 'AppDataLong'
    
    if not appDataClass:
      appDataClass = 'AppDataString'
      value = str(value)
    
    if isUnique:
      setUniqueAppData(appDataClass,parent,format,keyword,value)
    else:
      appData = getattr(Implementation,appDataClass)(application = format,keyword = keyword,value = value)
      parent.addApplicationData(appData)

    return True

  return False
예제 #21
0
    def setSpecificInfo(self):

        for parameterType in ['pH', 'Temperature', 'Pressure']:

            if hasattr(self, parameterType):
                setattr(self, parameterType,
                        returnFloat(getattr(self, parameterType)))
예제 #22
0
    def returnFloat(self, value):

        if value == 'nan':
            value = None
        else:
            value = returnFloat(value)

        return value
예제 #23
0
    def __init__(self, serial, chainCode, seqCode, atomName, atomNumber,
                 resName, x, y, z):

        self.serial = returnInt(serial)
        self.atomName = atomName.strip()
        self.atomNumber = returnInt(atomNumber)
        self.resName = resName.strip().upper()
        self.seqCode = seqCode
        self.chainCode = chainCode.strip()

        self.x = returnFloat(x)
        self.y = returnFloat(y)
        self.z = returnFloat(z)

        # Not supported
        self.insertionCode = defaultSeqInsertCode
        self.chainId = defaultMolCode
예제 #24
0
    def returnFloatValue(self, value):

        value = self.returnColumnValue(value)

        if value:
            value = returnFloat(value)

        return value
예제 #25
0
    def __init__(self, parent, atomSerial, name, x, y, z, atomType):

        self.parent = parent

        self.serial = returnInt(atomSerial)
        self.name = string.strip(name)

        self.x = returnFloat(x, verbose=0)
        self.y = returnFloat(y, verbose=0)
        self.z = returnFloat(z, verbose=0)

        self.atomType = string.strip(atomType)
        if not self.atomType:
            for char in self.name:
                if char not in '0123456789':
                    self.atomType = char
                    break
예제 #26
0
    def getValues(self, line):

        vals = []
        line = string.replace(line, '{', '')
        line = string.replace(line, '}', '')
        vallist = line.split()
        for i in range(0, len(vallist)):
            vals.append(returnFloat(vallist[i]))
        return vals
예제 #27
0
    def __init__(self, parent, type, value, error, units):

        # Warning: need to do some retyping here, data type not always correct in original NMR-STAR

        self.parent = parent
        self.type = type

        self.value = None

        if value:
            self.value = returnFloat(value)

        self.error = None

        if error:
            self.error = returnFloat(error)

        self.units = units
예제 #28
0
  def __init__(self,serial,atomName,resName,segId,seqCode,x,y,z, insertionCode = defaultSeqInsertCode):
  
    self.serial = returnInt(serial)    
    self.atomName = atomName.strip()
    self.resName = resName.strip()
    self.seqCode = returnInt(seqCode)
    self.x = returnFloat(x)
    self.y = returnFloat(y)
    self.z = returnFloat(z)
    self.insertionCode = insertionCode

    self.chainId = self.segId = segId.strip()
    if not self.chainId:
      self.chainId = defaultMolCode

    # Hack - the naming system is otherwise an esoteric mix of other ones
    if self.atomName == 'HN':
      self.atomName = 'H'
예제 #29
0
    def setValue(self, valueKey, values):

        if len(values) == 1:

            value = values[0]

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

                if valueKey == 'residue':
                    value = value.strip()
                    self.resLabel = value[0]

                    seqCodes = value[1:].split(',')
                    (self.seqCode,
                     self.seqInsertCode) = getSeqAndInsertCode(seqCodes[0])

                    if self.seqCode == None:
                        self.resLabel = value

                    # Can have multiple values - need to take care of that...
                    if len(seqCodes) > 1:
                        for seqCode in seqCodes[1:]:
                            self.otherSeqAndInsertCodes.append(
                                getSeqAndInsertCode(seqCode))

                elif valueKey == 'atom':
                    self.atomName = value.strip()

                elif valueKey == 'atomType':
                    self.atomType = value.strip()

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

                elif valueKey == 'chemShiftError':
                    self.valueError = returnFloat(value)

                elif valueKey == 'numAssignments':
                    self.numAssignments = returnInt(value)

        else:

            print "  Warning: empty or invalid data field %s for Sparky chemical shift file." % valueKey
            pass
예제 #30
0
    def __init__(self, value, atomName, seqCode, spinSystemId, resLabel,
                 defaultMolCode):

        self.value = returnFloat(value)
        self.atomName = atomName
        (self.seqCode, self.seqInsertCode) = getSeqAndInsertCode(seqCode)
        self.molCode = defaultMolCode
        self.resLabel = resLabel

        self.spinSystemId = spinSystemId
예제 #31
0
    def readWhatIfAsaInfoFile(self, fileName):
        'Return True on error.'

#        nTdebug('Now in ' + getCallerName() + ' for ' + fileName)
        fin = open(fileName)
        lines = fin.readlines()
        fin.close()
        atomsRead = 0
        _hydrogensSkipped = 0
        skipHydrogens = False # already corrected for elsewhere?
#        dataLine = False
        for line in lines:
            line = line.strip()
#            nTdebug('Line: ' + line)
            if line[0] == '*' or not line:
                continue

            fields = line.split(';')

            resLabel = fields[1]
            seqId = fields[2]
            insertionCode = fields[3]
            chainCode = fields[4]
            # field 5 has nothing?
            atomName = fields[6]
            accessibility = fields[7]
            
            
            if skipHydrogens and atomName[0] == 'H':
                _hydrogensSkipped += 1 # are zero anyway.
                continue
            
            if not insertionCode:
                insertionCode = ' '
            seqKey = (returnInt(seqId), insertionCode)

            if not (accessibility[0] == '|' and accessibility[-1] == '|'):
                nTerror("Skipping line without valid format for accessibility: " + line)
                continue
            if len(accessibility) < 3:
                nTerror("Skipping line with too short accessibility string: " + line)
                continue
            accessibilityStr = accessibility[1:-1]
            accessibilityStr = accessibilityStr.strip()
            if len(accessibilityStr) < 1:
                nTerror("Skipping line with empty accessibility string: " + line) # happens for PDB entry 1cjg for 2 residues
                continue         
            accessibility = returnFloat(accessibilityStr)
            d = self.allWhatIfInfo['chains']
            if not d.has_key(chainCode):
                d[chainCode] = {}
            if not d[chainCode].has_key(seqKey):                
                d[chainCode][seqKey] = {'hasBadAtoms': False, 'resLabel': resLabel, 'atoms': {}}
            if not d[chainCode][seqKey]['atoms'].has_key(atomName):
                d[chainCode][seqKey]['atoms'][atomName] = []

            d[chainCode][seqKey]['atoms'][atomName].append(accessibility)
            # TODO: match to cing data model for storage at atom level and to RDB cingresidue.wi_wsvacc using
            # WSVACC_STR
            atomsRead += 1
        # end for
#        nTdebug("Read %s atoms" % atomsRead)
#        nTdebug("Skipped %s hydrogen" % hydrogensSkipped)
#        nTdebug("Seen %s atoms" % (atomsRead + hydrogensSkipped))
        if not atomsRead:
            nTerror("Failed to read any atom")
            return True