Example #1
0
def findTopObjectPath(repositoryPath, topObject):
    """Get topObject absolute file path given the repositoryPath, 
  where topObject can be of class MemopsRoot or TopObject.
  
  Will find an existing file fitting the TopObject ID.
  If none is found returns default file name
  """

    suffix = fileSuffix
    lenSuffix = lenFileSuffix
    sep = separatorFileNameChar

    if topObject.root is topObject:
        # MemopsRoot
        objId = topObject.name
    else:
        # other TopObject
        objId = topObject.guid

    # get default file name
    topObjectDir = uniIo.joinPath(repositoryPath,
                                  *topObject.packageName.split('.'))
    result = uniIo.joinPath(topObjectDir, getTopObjectFile(topObject))

    if not os.path.isfile(result):
        # default file name is not there. Look for alternative file that fits ID
        if os.path.isdir(topObjectDir):
            for filename in os.listdir(topObjectDir):
                if filename.endswith(suffix):
                    if filename.split(sep)[-1][:-lenSuffix] == objId:
                        result = os.path.join(topObjectDir, filename)
                        break

    # return whatever result we have
    return result
Example #2
0
def parsePulProgName(name, fileLocation=None):
  """ Input: pulse program name to be parsed
             location of pulse program map file
             - if not given use standard file
      Output: List of (expName,isReversed) tuples
              expName can be either an NmrExpPrototype name 
              or a RefExperiment name.
              isReversed can be True, False, or None (meaning not set).
      
      Caches pulse program parsing map
  """
  
  global pulProgNameMap
  
  # get pulse program name translation map
  if fileLocation is None:
    if pulProgNameMap is None:
      fileLocation = uniIo.joinPath(uniIo.getTopDirectory(), 'data', 'ccp', 
                                    'bruker', 'BrukerPulseProgMap.xml')
      parseInfo = ccpGenUtil.loadAllParseInfo(fileLocation)
      pulProgNameMap = ccpGenUtil.convertParseInfo(parseInfo)
  
  else:
    parseInfo = ccpGenUtil.loadAllParseInfo(fileLocation)
    pulProgNameMap = ccpGenUtil.convertParseInfo(parseInfo)
  
  # get match result
  matchMap = matchName(name, pulProgNameMap, specialCases)
  dd = matchMap
  
  return matchMap['matches']
Example #3
0
def testNameParsing(dirPath):
  """ Frame code to run name testing
  """
  
  # set of imput info
  stdInfoFile = uniIo.joinPath(uniIo.getTopDirectory(),
                               'data', 'ccp', 'bruker', 'BrukerPulseProgMap.xml')
  fileNames = os.listdir(dirPath)
  fileNames.sort()
  parseInfo = ccpGenUtil.loadAllParseInfo(stdInfoFile)
  useInfo = ccpGenUtil.convertParseInfo(parseInfo)
  
  # set up mapId:list dictionary
  matchByMap = {}
  notmatched = []
  skipped = []
  for expNameMap in parseInfo['expNameMaps']:
    matchByMap[id(expNameMap)] = []
  
  # match filenames and store by matchDict
  for fname in fileNames:
    dd = matchName(fname, useInfo, specialCases)
    dd['fname'] = fname
    expNameMap = dd.get('expNameMap')
    if (dd.get('status') == 'skip' 
        or not os.path.isfile(uniIo.joinPath(dirPath,fname))):
      skipped.append(dd)
    elif expNameMap is None:
      notmatched.append(dd)
    else:
      matchByMap[id(expNameMap)].append(dd)
    #print fname, dd['matches'], dd['names'], dd['unused']
  
  # print result
  print '\nSKIPPED:'
  for dd in skipped:
    print '    - ', dd['fname'], dd.get('usenames'), dd.get('prefixes'), dd.get('unused') 

  print '\nNO MATCH:'
  for dd in notmatched:
    print '    - ', dd['fname'], dd.get('usenames'), dd.get('prefixes'), dd.get('unused') 

  unused = []
  for xmap in parseInfo['expNameMaps']:
    ll = matchByMap[id(xmap)]
    prototypes = [(x.get('name'), x.get('isReversed')) for x in xmap['expPrototypes']]
    if ll:
      print '\nMATCH:', xmap.get('namesStartWith'), xmap.get('hasnames'), xmap.get('hasprefixes')
      print '      ', prototypes
      for dd in ll:
        if dd.get('unused'):
          ss = ' NB - '
        else:
          ss = '    - '
          
        print ss, dd['fname'], dd.get('usenames'), dd.get('prefixes'), dd.get('unused')
          
  for xmap in unused:
    print '\nUNUSED', xmap.get('namesStartWith'), xmap.get('hasnames'), xmap.get('hasprefixes') 
    print '      ', [(x.get('name'), x.get('isReversed')) for x in xmap['expPrototypes']]
Example #4
0
def getCcpForgeUrls(molType, ccpCode, sourceName=None):
    """
  Creates the URL info for ChemComp(Coord) downloads from CcpForge
  """

    ccpForgeUrl = "http://ccpforge.cse.rl.ac.uk/gf/project/ccpn-chemcomp/scmcvs/?action=browse&root=ccpn-chemcomp&pathrev=MAIN&path=/"
    checkOutDir = "~checkout~"
    archiveDir = "ccpn-chemcomp/data/pdbe/chemComp/archive/"

    #%2Acheckout%2A%2Fccpn-chemcomp%2Fdata%2Fpdbe%2FchemComp%2Farchive%2FChemComp%2Fprotein%2Fprotein%252B004%252Bpdbe_ccpnRef_2010-09-23-14-41-20-237_00001.xml&revision=1.1

    if not sourceName:
        fileType = 'ChemComp'
        subPath = getChemCompArchiveXmlFilePath("", molType, ccpCode)

    else:
        fileType = 'ChemCompCoord'
        subPath = getChemCompCoordArchiveXmlFilePath("", sourceName, molType,
                                                     ccpCode)

    # wb104: 15 Dec 2010: need to use joinPath because otherwise does not
    # work on Windows, but cannot stick ccpForgeUrl in joinPath() because
    # that would convert http:// to http:/
    ccpForgeDirUrl = ccpForgeUrl + uniIo.joinPath(archiveDir, fileType,
                                                  subPath)
    ccpForgeDownloadUrl = ccpForgeUrl + uniIo.joinPath(checkOutDir, archiveDir,
                                                       fileType, subPath)

    return (fileType, ccpForgeDirUrl, ccpForgeDownloadUrl)
Example #5
0
def getDataPath(*args):
    """
  Gives location of data path. Extra args are added on as extra directories
  Result ends with the last arg (which might be either a file or a dictionary)
  """
    dataPath = uniIo.joinPath(uniIo.getTopDirectory(), 'data', *args)
    return dataPath
Example #6
0
def getChemCompArchiveXmlFilePath(chemCompPath, molType, ccpCode):

    chemCompXmlFilePath = uniIo.joinPath(chemCompPath, molType)

    if molType == 'other':
        chemCompXmlFilePath = uniIo.joinPath(chemCompXmlFilePath, ccpCode[0])

    return chemCompXmlFilePath
Example #7
0
def setDataSourceDataStore(dataSource,
                           dataUrlPath,
                           localPath,
                           dataLocationStore=None,
                           dataUrl=None):

    #
    # Get DataLocationStore
    #

    if not dataLocationStore:

        setCurrentStore(dataSource.root, 'DataLocationStore')
        dataLocationStore = dataSource.root.currentDataLocationStore

    #
    # Get (or create) DataUrl
    #

    # TODO should this search function go elsewhere?
    if not dataUrl:
        for tmpDataUrl in dataLocationStore.dataUrls:
            if tmpDataUrl.url.dataLocation == dataUrlPath:
                dataUrl = tmpDataUrl

        if not dataUrl:
            dataUrlPath = uniIo.normalisePath(dataUrlPath)
            dataUrl = dataLocationStore.newDataUrl(url=Implementation.Url(
                path=dataUrlPath))

    #
    # Create a BlockedBinaryMatrix. TODO: could be other classes that are set up this way - rename func and make general,, pass in class?
    #
    localPath = uniIo.normalisePath(localPath)
    blockedBinaryMatrix = dataLocationStore.newBlockedBinaryMatrix(
        path=localPath, dataUrl=dataUrl)
    """
  TODO Set here as well, or do this later after returning object:

blockSizes      Int      0..*     Block sizes in dimension order  
complexStoredBy   ComplexStorage   1..1   The ordering of real and imaginary parts of hypercomplex numbers in the data matrix. See ComplexStorage type for details  
hasBlockPadding   Boolean   1..1   Are data padded to fill all blocks completely? Alternatively incomplete blocks store only the actual data.  
headerSize   Int   1..1   Header size in bytes  
isBigEndian   Boolean   1..1   Are data big-endian (alternative little-endian).  
isComplex   Boolean   0..*   Are numbers complex (if True) or real/integer (if False).  
nByte   Int   1..1   Number of bytes per number  
numPoints   Int   0..*   number of points for each matrix dimension - also defines dimensionality of matrix. The number of points is the same for real or complex data, in the sense that n complex points require 2n real numbers for storage.  
numRecords   Int   1..1   Number of matrix records in file. All other information in the object describes a single record.  
numberType   NumberType   1..1   Type of numbers held in matrix  
  
  """

    dataSource.dataStore = blockedBinaryMatrix

    return blockedBinaryMatrix
Example #8
0
def prepareLocalExecution(nmrCalcRun, targetDir):
    """ return [procArgs, targetDir, logFile list for later, local execution
  And carry out any preliminary commands
  """

    # Set up parameters for program call
    shellParObj = nmrCalcRun.findFirstRunParameter(name='programCall')
    if shellParObj is None:
        raise Exception("Parameter name=programCall not found")
    else:
        shellCall = shellParObj.textValue

    executeScript = os.path.join(os.path.expandvars(programBin), shellCall)

    fileNameObj = nmrCalcRun.findFirstRunParameter(name='fileNameSetup')
    if fileNameObj is None:
        raise Exception("no 'fileNameSetup' parameter found")
    filePath = uniIo.joinPath(targetDir, fileNameObj.textValue)

    procargs = [executeScript, '-f', filePath]

    algObj = nmrCalcRun.findFirstRunParameter(name='MDAlgorithm')
    if 'XPLOR' in algObj.textValue.upper():
        # copy xplor template files
        for fname in ('sa.inp', 'generate.inp', 'generate_template.inp'):
            src = os.path.join(os.path.expandvars(unioXplor), fname)
            shutil.copy2(src, targetDir)

    #
    return (procargs, targetDir)
Example #9
0
def configParameter(keyWord):
    """Get configuration parameter corresponding to 'keyWord'.
  
  NBNB TBD this should go to a configuration file to get its data
  The format of this file is still up for grabs.
  """

    rootDir = uniIo.normalisePath(uniIo.os.getcwd())

    if keyWord == 'repositories':
        # list of (name,urlPath) pairs
        return []

    elif keyWord == 'packageLocators':
        # list of (packageName, repositoryName) Triplets
        # If the packageName appears more than once, the named repositories
        # are added in the order given
        return [
            ('ccp.molecule.ChemComp', 'userData'),
            ('ccp.molecule.ChemComp', 'refData'),
            ('ccp.molecule.ChemCompCharge', 'refData'),
            ('ccp.molecule.ChemCompCoord', 'refData'),
            ('ccp.molecule.ChemCompLabel', 'userData'),
            ('ccp.molecule.ChemCompLabel', 'refData'),
            ('ccp.molecule.ChemElement', 'refData'),
            ('ccp.molecule.StereoChemistry', 'refData'),
            ('ccp.nmr.NmrExpPrototype', 'userData'),
            ('ccp.nmr.NmrExpPrototype', 'refData'),
            ('ccp.nmr.NmrReference', 'refData'),
            ('ccpnmr.AnalysisProfile', 'generalData'),
            ('ccpnmr.AnalysisProfile', 'refData'),
        ]

    else:
        return None
Example #10
0
def fixImplementation(topObj, delayDataDict):
  """ Add generalData repository, packageLocator for AnalysisProfile with
  repositories link, and set
  
  NB when this is called PAckageLocators and Repositories
  have already had their child links and crosslinks set.
  """
  from memops.universal import Io as uniIo
  from memops.api.Implementation import Url
  import os.path
  
  emptyDict = {}
  emptyList = []
  doGet = delayDataDict.get
  urlPath = uniIo.normalisePath(os.path.expanduser('~/.ccpn/data'))
  repositories = doGet(topObj).get('repositories')
  for refData in repositories:
    if refData.name == 'refData':
      break
  else:
    raise ApiError("refData repository not found")
  genData = topObj.newRepository(name='generalData', url=Url(path=urlPath))
  topObj.__dict__['repositories']['generalData'] = genData
  
  profileLocator = topObj.newPackageLocator(targetName='ccpnmr.AnalysisProfile',
                                             repositories=(genData, refData))
  topObj.__dict__['packageLocators']['ccpnmr.AnalysisProfile'] = profileLocator
Example #11
0
    def __init__(self):
        """ parameters are mandatoryInitParams, optionalInitParams
    and the special optional
    """

        for tag in TextWriter_py_2_1.mandatoryAttributes:
            if not hasattr(self, tag):
                raise MemopsError(" TextWriter lacks mandatory %s attribute" %
                                  tag)

        super(TextWriter, self).__init__()

        # special parameters: optional with default values
        if self.rootFileName is None:
            self.rootFileName = ImpConstants.rootPackageDirName

        if self.rootDirName is None:
            self.rootDirName = uniIo.getTopDirectory()

        self.fp = None
        self.fileName = ''
        self.indent = 0
        self.indents = []
        self.errorMsg = ''

        self.previousLineEmpty = False  # used so that do not print out two '\n' in a row
Example #12
0
def prepareLocalExecution(nmrCalcRun, targetDir):
    """ return [procArgs, targetDir, logFile list for later, local execution
  And carry out any preliminary commands
  """

    # Set up parameters for program call
    shellParObj = nmrCalcRun.findFirstRunParameter(name='programCall')
    if shellParObj is None:
        raise Exception("Parameter name=programCall not found")
    else:
        shellCall = shellParObj.textValue

    executeScript = os.path.join(os.path.expandvars(programBin), shellCall)
    executeScript2 = os.path.join(os.path.expandvars(programBin), 'cyanatable')

    fileNameObj = nmrCalcRun.findFirstRunParameter(name='fileNameSetup')
    if fileNameObj is None:
        raise Exception("no 'fileNameSetup' parameter found")
    filePath = uniIo.joinPath(targetDir, fileNameObj.textValue)

    procargs = [executeScript, filePath]
    procargs2 = [executeScript2]

    #
    return (procargs, targetDir, procargs2)
Example #13
0
def setLicenses(directory=None,
                licenseDir='license',
                warnSkippedFiles=(not 0),
                mode='act'):
    """ wrapper - set license header for 'directory' and all subdirectories
   
  licenseDir is the relative path from 'directory'
  to the directory with license texts
  """

    # necessary as the first directory may be a relative directory name,
    # playing havoc with import commands
    firstLookupDir = sys.path[0]
    sys.path[0] = ''

    try:
        global testInfo
        testInfo = {}

        if directory is None:
            directory = uniIo.getTopDirectory()
        else:
            directory = os.path.abspath(directory)

        doSetLicenses(directory, licenseDir, None, 0, warnSkippedFiles, mode)

        if mode == 'test':
            print showTestInfo()

    finally:
        sys.path[0] = firstLookupDir
Example #14
0
def read(nmrCalcRun, dataDir):
    """ Read Output files for Unio run
    Input:
      nmrCalcRun: NmrCalc.Run 
      dataDir: directory directly containing program output.
  """

    fileNames = stdFileNames.copy()

    # make summary text element
    summary = ""
    for tag in ('overview', ):
        path = uniIo.joinPath(dataDir, fileNames[tag])
        if os.path.isfile(path):
            txt = open(path).read()
        else:
            txt = 'WARNING, file % not found' % fileNames[tag]
        summary += ('-' * 80 +
                    "\nFROM FILE :      %s\n----------------\n%s\n\n\n" %
                    (fileNames[tag], txt))

    nmrCalcRun.newRunParameter(name='summary',
                               ioRole='output',
                               textValue=summary)

    # Get MolSystem
    molResidueData = (
        nmrCalcRun.findFirstData(className='MolResidueData', ioRole='input')
        or nmrCalcRun.findFirstData(className='MolSystemData', ioRole='input'))
    molSystem = molResidueData.molSystem

    # read pdb structures
    path = uniIo.joinPath(dataDir, fileNames['pdbBundle'])
    if os.path.isfile(path):
        ensemble = StructureIo.getStructureFromFile(molSystem, path)

    # make EnsembleData
    nmrCalcRun.newStructureEnsembleData(name='result',
                                        ioRole='output',
                                        structureEnsemble=ensemble,
                                        details="Unio calculated structures")

    # Make Nmr.StructureCalculation
    nmrProject = nmrCalcRun.nmrCalcStore.nmrProject
    nmrCalcRun.structureGeneration = nmrProject.newStructureGeneration(
        generationType='denovo', name='UNIO', structureEnsemble=ensemble)
Example #15
0
def getChemCompOrCoordXmlFile(repository, fileSearchString, fileSearchPath,
                              className, identifier, showError, copyFile):

    result = None

    if showError is None:
        showError = uniIo.printError

    # Try to find file...

    import glob
    fileNameMatches = glob.glob(
        uniIo.joinPath(fileSearchPath, fileSearchString))

    if fileNameMatches:
        if len(fileNameMatches) > 1:
            errorText = "Error: multiple matches found for %s %s - taking last one." % (
                className, identifier)
            showError("Multiple %s matches" % className, errorText)

        filePath = fileNameMatches[-1]
        (fileDir, fileName) = os.path.split(filePath)

        #
        # Copy file if found...
        #

        if os.path.exists(filePath):
            if copyFile:
                savePath = repository.getFileLocation('ccp.molecule.%s' %
                                                      className)
                if not os.path.exists(savePath):
                    os.makedirs(savePath)
                import shutil
                saveFilePath = uniIo.joinPath(savePath, fileName)
                shutil.copy(filePath, saveFilePath)
                result = saveFilePath

                print "  %s file %s copied to %s..." % (className, fileName,
                                                        savePath)

            else:
                result = filePath

    return result
Example #16
0
def saveProject(project, name='test', subDir='data'):

    # Find the backup repository and set the right path for it.
    backupRepos = project.findFirstRepository(name='backup')
    backupPath = uniIo.joinPath(os.getcwd(), subDir, name + '_backup')

    # Create a URL for the backup repository.
    backupRepos.url = Url(path=backupPath)

    # Do the same for the repository containing the data in the project.
    projectRepos = project.findFirstRepository(name='userData')
    newPath = uniIo.joinPath(os.getcwd(), subDir, name)

    # And also for the URL of this data.
    projectRepos.url = Url(path=newPath)

    # This saves the project to the path specified by the URL for the
    # 'userData' repository.
    project.saveModified()
Example #17
0
def oldwrite(nmrCalcRun, topDir=None):
  """ Write input files for Program run
    Input:
      nmrCalcRun: NmrCalc.Run 
      topDir: optional destination directory.
  """
  targetDir = intIo.createTargetDir(nmrCalcRun, topDir=topDir)
  
  # write Properties file
  propDict, dummy = intIo.makeParameterDict(nmrCalcRun)
  propFile = uniIo.joinPath(targetDir, intIo.propFileName)
  open(propFile,'w').write(json.dumps(propDict, sort_keys=True, 
                                      indent=intIo.propIndent))
  
  # Write data file
  
  # get file
  inpFile = propDict.get('INPUT_FILE')
  if inpFile:
    talosInputFile = uniIo.joinPath(targetDir, inpFile)
  else:
    raise Exception("No code=INPUT_FILE RunParameter in nmrCalcRun")
  
  # Get shiftList
  shiftList = intUtil.getMeasurementList(nmrCalcRun)
  if shiftList is None:
    raise Exception("Run must have exactly one shift list, %s found" % len(ll))
  
  # Get residues
  ll = list(nmrCalcRun.findAllData(className='MolResidueData'))
  if len(ll) == 1:
    obj =  ll.pop()
    residues = list(obj.residues)
    residues.sort(key=operator.attrgetter('seqId'))
    if len(set(obj.chainCodes)) != 1:
      raise Exception("Run MolResidueData did not have a (single) chain" )
  else:
    raise Exception("Run must have excactly one MolResidueData, %s found" % len(ll))
  
  #  
  talosIo.writeShiftFile(open(talosInputFile,'w'), residues, shiftList,
                         propDict.get('minShiftQuality'))
Example #18
0
def getProjectFile(repositoryPath, projectName=None):
    """Get project file given the repositoryPath and optionally the projectName
     (if none given then determined from repositoryPath)
  """

    if not projectName:
        projectName = os.path.basename(repositoryPath)

    implDirectory = getImplementationDirectory(repositoryPath)

    return uniIo.joinPath(implDirectory, projectName + fileSuffix)
Example #19
0
def write(nmrCalcRun, targetDir):
    """ Write input files for Program run
    Input:
      nmrCalcRun: NmrCalc.Run 
      targetDir: destination directory.
  """

    intIo.writeDataFiles(nmrCalcRun, targetDir)

    jsonDict = intIo.makeJsonDict(nmrCalcRun)

    # write properties file
    propFile = uniIo.joinPath(targetDir, intIo.propFileName)
    open(propFile, 'w').write(
        json.dumps(jsonDict, sort_keys=True, indent=intIo.propIndent))

    # Write program setup file
    fileNameObj = nmrCalcRun.findFirstRunParameter(name='fileNameSetup')
    if fileNameObj is not None:
        filePath = uniIo.joinPath(targetDir, fileNameObj.textValue)
        writeSetupFile(filePath, jsonDict)
Example #20
0
def write(nmrCalcRun, targetDir):
    """ Write input files for Program run
    Input:
      nmrCalcRun: NmrCalc.Run
      targetDir: destination directory.
  """

    intIo.writeDataFiles(nmrCalcRun, targetDir)

    jsonDict = intIo.makeJsonDict(nmrCalcRun)

    # write properties file
    propFile = uniIo.joinPath(targetDir, intIo.propFileName)
    print 'About to write', propFile
    open(propFile, 'w').write(
        json.dumps(jsonDict, sort_keys=True, indent=intIo.propIndent))

    # Write program setup file
    fileNameObj = nmrCalcRun.findFirstRunParameter(name='fileNameSetup')
    importJsonName = 'cyana2ccpn.json'
    if fileNameObj is not None:

        # write init.cya
        initFile = uniIo.joinPath(targetDir, initFileName)
        rmsdrange = jsonDict['RunParameter'].pop('rmsdrange')
        seqFile = jsonDict['RunParameter'].pop('fileNameSequence')
        text = """# Cyana init file - Generated by CcpNmr Integrator
rmsdrange:=%s
cyanalib
read seq %s
""" % (rmsdrange, seqFile)
        open(initFile, 'w').write(text)

        # write main command file
        filePath = uniIo.joinPath(targetDir, fileNameObj.textValue)
        importFilePath = uniIo.joinPath(targetDir, importJsonName)
        writeSetupFile(filePath, jsonDict)
        writeImportJson(importFilePath, jsonDict)
Example #21
0
    def getDetails(self, fullfile):

        details = ''
        if os.path.isfile(fullfile):
            format = self.formatPulldown.getText()
            detailsDir = os.path.dirname(fullfile)
            detailsFile = uniIo.joinPath(detailsDir, details_file_dict[format])
            if os.path.exists(detailsFile):
                fp = open(detailsFile)
                details = fp.read().strip().replace('\n',
                                                    ' ').replace('\r', ' ')
                fp.close()

        return (details, )
Example #22
0
def getDataStoringFromFilepath(memopsRoot,
                               fullFilePath,
                               preferDataUrls=None,
                               dataLocationStore=None,
                               keepDirectories=1):

    # make absolute,, normalised path
    fullFilePath = uniIo.normalisePath(fullFilePath, makeAbsolute=True)

    dataUrl, filePath = findDataStoringFromFilepath(memopsRoot, fullFilePath,
                                                    preferDataUrls,
                                                    dataLocationStore,
                                                    keepDirectories)

    if dataUrl is None:

        urlPath = uniIo.normalisePath((fullFilePath[:-len(filePath)]))
        dataLocationStore = memopsRoot.currentDataLocationStore
        dataUrl = dataLocationStore.newDataUrl(url=Implementation.Url(
            path=urlPath))
        dataUrl.name = 'auto-%s' % dataUrl.serial
    #
    return (dataUrl, filePath)
Example #23
0
def resetPackageLocators(project):

    carbDataPath = uniIo.normalisePath(
        os.path.join(os.path.abspath('..'), 'data'))

    print 'Location of local carbohydrate ChemComps: [%s]' % carbDataPath

    carbDataUrl = Implementation.Url(path=carbDataPath)

    carbDataRepos = project.newRepository(name='carbData', url=carbDataUrl)

    chemPackLoc = project.findFirstPackageLocator(
        targetName='ccp.molecule.ChemComp')

    chemPackLoc.addRepository(carbDataRepos)
Example #24
0
def write(nmrCalcRun, targetDir):
    """ Write input files for Program run
    Input:
      nmrCalcRun: NmrCalc.Run 
      targetDir: destination directory.
  """

    #intIo.writeDataFiles(nmrCalcRun, targetDir)

    jsonDict = intIo.makeJsonDict(nmrCalcRun)

    # write properties file
    propFile = uniIo.joinPath(targetDir, intIo.propFileName)
    print 'About to write', propFile
    open(propFile, 'w').write(
        json.dumps(jsonDict, sort_keys=True, indent=intIo.propIndent))
Example #25
0
def getPossibleProjectFiles(repositoryPath):
    """Get the possible project files given the repositoryPath
  """

    if os.path.isdir(repositoryPath):
        implDirectory = getImplementationDirectory(repositoryPath)
        if os.path.isdir(implDirectory):
            files = os.listdir(implDirectory)
            files = [
                uniIo.joinPath(implDirectory, file) for file in files
                if file.endswith(fileSuffix)
            ]

            return files

    return []
Example #26
0
    def __init__(self, **kw):
        """To make this work under python 2.1 we need to inline the inits
    of several other files.
    """

        # set input attributes
        for (tag, val) in kw.items():
            if not hasattr(self, tag):
                setattr(self, tag, val)

        # in-line set xml settings (in lieu of Language init)
        settings = TextWriter_py_2_1.settings['xmlmodel']
        for (tag, val) in settings.items():
            if not hasattr(self, tag):
                setattr(self, tag, val)

        # in-line version of TextWriter init
        for tag in TextWriter_py_2_1.mandatoryAttributes:
            if not hasattr(self, tag):
                raise MemopsError(" TextWriter lacks mandatory %s attribute" %
                                  tag)

        # special parameters: optional with default values
        if self.rootFileName is None:
            self.rootFileName = ImpConstants.rootPackageDirName

        if self.rootDirName is None:
            self.rootDirName = uniIo.getTopDirectory()

        # process self.includePackageNames, including container names
        inclNames = self.includePackageNames
        if inclNames:
            for name in inclNames:
                ll = name.split('.')
                for ii in range(1, len(ll)):
                    ss = '.'.join(ll[:ii])
                    if ss not in inclNames:
                        inclNames.append(ss)

        self.fp = None
        self.fileName = ''
        self.indent = 0
        self.indents = []
        self.errorMsg = ''
        self.previousLineEmpty = False  # used so that do not print out two '\n' in a row
Example #27
0
def changeDataStoreUrl(dataStore, newPath):
    """ Change the url for this dataStore, so at the end we have
  dataStore.dataUrl.url.path = newPath.  This changes all dataUrls
  with the same old path if the old path does not exist and the
  new one does.
  """

    newPath = uniIo.normalisePath(newPath, makeAbsolute=True)
    oldDataUrl = dataStore.dataUrl
    oldUrl = oldDataUrl.url
    oldPath = oldUrl.dataLocation
    oldExists = os.path.exists(oldPath)
    if newPath != oldPath:
        dataLocationStore = dataStore.dataLocationStore
        newUrl = Implementation.Url(
            path=newPath)  # TBD: should use oldUrl.clone(path=newPath)

        # first check if have a dataUrl with this path
        newDataUrl = dataLocationStore.findFirstDataUrl(url=newUrl)
        if not newDataUrl:
            # if old path exists and there is more than one dataStore with
            # this dataUrl then create new one
            dataUrlStores = dataLocationStore.findAllDataStores(
                dataUrl=oldDataUrl)
            if oldExists and len(dataUrlStores) > 1:
                newDataUrl = dataLocationStore.newDataUrl(name=oldDataUrl.name,
                                                          url=newUrl)

        # if have found or have created newDataUrl then set dataStore to point to it
        # else just change url of oldDataUrl (which could affect other dataStores)
        if newDataUrl:
            dataStore.dataUrl = newDataUrl
        else:
            oldDataUrl.url = newUrl

        # if old path does not exist and new path exists then change urls of
        # all data urls which have old path to new path (there might be none)
        if not oldExists:
            newExists = os.path.exists(newPath)
            if newExists:
                for dataUrl in dataLocationStore.dataUrls:
                    if dataUrl.url == oldUrl:
                        dataUrl.url = newUrl
Example #28
0
def loadProject(parent, path, projectName=None):

    path = uniIo.normalisePath(path)
    askdir = lambda title, prompt, initial_value: askDir(
        title, prompt, initial_value, parent=parent, extra_dismiss_text='Skip')
    askfile = lambda title, prompt, initial_value: askFile(
        title, prompt, initial_value, parent=parent, extra_dismiss_text='Skip')
    project = genIo.loadProject(path,
                                showWarning=showWarning,
                                askDir=askdir,
                                askFile=askfile)

    # now check dataStores
    # delete those that are not used
    # and otherwise check path to see if exists

    dataStores = []
    for dataLocationStore in project.dataLocationStores:
        for dataStore in dataLocationStore.dataStores:
            if isinstance(dataStore,
                          NumericMatrix) and not dataStore.nmrDataSources:
                print 'deleting dataStore %s with path %s' % (
                    dataStore, dataStore.fullPath)
                dataStore.delete()
            elif isinstance(
                    dataStore,
                    MimeTypeDataStore) and not dataStore.nmrDataSourceImages:
                print 'deleting dataStore %s with path %s' % (
                    dataStore, dataStore.fullPath)
                dataStore.delete()
            else:
                dataStores.append(dataStore)

    badDataStores = [
        dataStore for dataStore in dataStores
        if not os.path.exists(dataStore.fullPath)
    ]

    if badDataStores:
        popup = DataLocationPopup(parent, project, modal=True)
        popup.destroy()

    return project
Example #29
0
    def getObjFileName(self, metaObj, absoluteName=True, addSuffix=False):
        """ Get filename for metaObj
    If absoluteName is True the file name is absolute
    otherwise it is relative to the relevant baseDir
    """

        # absoulte or relative path
        if absoluteName:
            pathList = [self.rootDirName, self.baseDirName]
        else:
            pathList = []

        if metaObj.container is None:
            # Root package only
            pathList.append(ImpConstants.modellingPackageName)
            if self.codeDirName:
                pathList.append(self.codeDirName)
            pathList.append(self.rootFileName)

        else:
            # any other object
            ll = metaObj.qualifiedName().split('.')
            if self.codeDirName:
                ll[1:1] = [self.codeDirName]
            pathList.extend(ll)

            # special handling for ModelElements that may correspond to directories:
            if (isinstance(metaObj, MetaModel.MetaPackage) and
                (metaObj.containedPackages or not self.classesInPackage)):
                pathList.append(self.packageFile)

            elif not isinstance(metaObj.container, MetaModel.MetaPackage):
                raise MemopsError(
                    " file names not implemented for objects of type %s" %
                    (metaObj.__class__.__name__, ))

        # add suffix
        if addSuffix and self.fileSuffix:
            pathList[-1] = '%s.%s' % (pathList[-1], self.fileSuffix)

        #
        return uniIo.joinPath(*pathList)
Example #30
0
def fullLoadValidationStore(topObj):
    """hard load ValidationStore from old location
  """

    from memops.format.xml import Util as xmlUtil
    from memops.universal import Io as uniIo
    from memops.format.xml import XmlIO
    root = topObj.memopsRoot
    locator = (
        root.findFirstPackageLocator(targetName='ccp.molecule.Validation')
        or root.findFirstPackageLocator(targetName='any'))
    repository = locator.findFirstRepository()
    #repository = topObj.activeRepositories[0]
    fileLocation = repository.getFileLocation(
        'ccp.molecule.StructureValidation')
    filePath = uniIo.joinPath(fileLocation, xmlUtil.getTopObjectFile(topObj))
    XmlIO.loadFromStream(open(filePath),
                         topObject=topObj,
                         topObjId=topObj.guid,
                         partialLoad=False)
Example #31
0
###################
# Main of program #
###################

if __name__ == "__main__":
  
  #
  # Variables...
  #
  
  dataDir = 'data/'
  sequenceFileName = 'fasta.seq'

  currentDir = os.path.abspath('.')
  projectDir = uniIo.joinPath((currentDir,'local'))
  projectName = 'testImportSequence'
  
  #
  # Make sure the projectDir exists and delete existing data
  #
  
  if not os.path.exists(projectDir):
    os.mkdir(projectDir)

  projectPath = os.path.join(projectDir,projectName)
  if os.path.exists(projectPath):
    shutil.rmtree(projectPath)

  #
  # Create a CCPN project. This sets default save locations in the
Example #32
0
  
  #
  # Make sure it saves the information in the projectDir
  # To do this on the Python level you have to reset the path
  # for the urls that indicate the directory locations for the
  # saved files...
  #
  # Alternatively create the project in the right directory to
  # start with - see convertCns2Pdb
  #
  
  for repository in ccpnProject.repositories:
    
    if repository.name in ('userData','backup'):
      
      (oldUrlPath,baseName) = uniIo.splitPath((repository.url.path))
      newUrlPath = uniIo.joinPath(projectDir,baseName)
      
      repository.url = Implementation.Url(path = newUrlPath)

  #
  # Create main Tk window for popups
  #

  gui = Tkinter.Tk()

  #
  # Create an NmrView class and read in the files... create an experiment
  # for the peak list beforehand and pass in the parameters.
  #