Example #1
0
    def checkProject(self,
                     ccpnProject=None,
                     ccpnDir=None,
                     structureEnsembleId=None,
                     shiftListSerial=None):

        if self.showMessages:
            print drawBox(" VASCO: calculating rereferencing...")

        #
        # Get info from CCPN project
        #

        if ccpnProject:
            self.ccpnProject = ccpnProject
        elif ccpnDir:
            self.ccpnProject = loadProject(ccpnDir)
        elif self.ccpnDir:
            self.ccpnProject = loadProject(self.ccpnDir)
        else:
            from memops.editor.OpenProjectPopup import OpenProjectPopup
            _popup = OpenProjectPopup(self.guiParent,
                                      callback=self.initProject,
                                      modal=True)

        #
        # Get the relevant structureEnsemble
        #

        self.selectStructureEnsemble(structureEnsembleId=structureEnsembleId)

        #
        # Get the right shift list
        #

        self.selectShiftList(shiftListSerial=shiftListSerial)

        #
        # Prep the data
        #

        self.prepareData()

        #
        # Create a dictionary to run VASCO on
        #

        self.createEntryDict()

        #
        # Get VASCO reref data
        #

        self.getVascoRerefInfo()
Example #2
0
  def checkProject(self,ccpnProject=None,ccpnDir=None,structureEnsembleId=None,shiftListSerial=None):

    if self.showMessages:
        print drawBox(" VASCO: calculating rereferencing...")

    #
    # Get info from CCPN project
    #
    
    if ccpnProject:
      self.ccpnProject = ccpnProject
    elif ccpnDir:
      self.ccpnProject = loadProject(ccpnDir)
    elif self.ccpnDir:
      self.ccpnProject = loadProject(self.ccpnDir)
    else:
      from memops.editor.OpenProjectPopup import OpenProjectPopup
      _popup = OpenProjectPopup(self.guiParent, callback = self.initProject, modal=True)
    
    #
    # Get the relevant structureEnsemble
    #
    
    self.selectStructureEnsemble(structureEnsembleId=structureEnsembleId)
      
    #
    # Get the right shift list
    #
    
    self.selectShiftList(shiftListSerial=shiftListSerial)
          
    #
    # Prep the data
    #
    
    self.prepareData()
    
    #
    # Create a dictionary to run VASCO on
    #

    self.createEntryDict()
    
    #
    # Get VASCO reref data
    #
    
    self.getVascoRerefInfo()    
Example #3
0
def launchApplication(projectDir=None):

  global top

  root = Tkinter.Tk()
  root.withdraw()
  top  = EntryCompletionGui(root)
 
  project = None
  if projectDir:
    projectDir = normalisePath(projectDir)
    askdir  = lambda title, prompt, initial_value, default_dir: askDir(title, prompt,
              initial_value, parent=top, extra_dismiss_text='Skip')
    askfile = lambda title, prompt, initial_value: askFile(title, prompt,
              initial_value, parent=top, extra_dismiss_text='Skip')
    try:
      project = loadProject(path=projectDir, showWarning=showWarning, askDir=askdir, askFile=askfile)

      userRepos = project.findFirstRepository(name='userData')
      chemCompPackLoc = project.findFirstPackageLocator(targetName='ccp.molecule.ChemComp')

      if userRepos not in chemCompPackLoc.repositories:
        chemCompPackLoc.addRepository(userRepos)

    except ApiError, e:
      showError('Reading project', e.error_msg, parent=top)
Example #4
0
    def checkAllShiftLists(self):
        """
        Return True on error
        """
        if not self.showMessages:
            #            print 'switching messaging off temporarily.'
            switchOutput(False)
        ccpnProject = loadProject(self.ccpnDir)
        if not self.showMessages:
            print 'switching messaging on again.'
            switchOutput(True)
        if ccpnProject == None:
            nTerror("Failed to load CCPN project from: %s" % self.ccpnDir)
            return True

#        shiftLoL = ccpnProject.currentNmrProject.findAllMeasurementLists(className='ShiftList')
# Use sorting by CCPN.
        shiftLoL = filterListByObjectClassName(
            ccpnProject.currentNmrProject.sortedMeasurementLists(),
            Ccpn.CCPN_CS_LIST)
        #        nTdebug("Working on shiftLoL %s", str(shiftLoL))

        for i, shiftList in enumerate(shiftLoL):
            shiftListSerial = shiftList.serial
            #            nTdebug("Working on shiftListSerial %s", shiftListSerial)
            self.checkProject(ccpnProject=ccpnProject,
                              shiftListSerial=shiftListSerial)
            self.tagProject()
            if self.tagCingProject(shiftList, i):
                return True
Example #5
0
def launchApplication(projectDir=None):

    global top

    root = Tkinter.Tk()
    root.withdraw(
    )  # get rid of the root window Tkinter would otherwise put up
    top = ApplicationPopup(
        root)  # creates our controlled window (this class in fact)

    project = None
    if projectDir:
        projectDir = normalisePath(projectDir)
        askdir = lambda title, prompt, initial_value, default_dir: askDir(
            title,
            prompt,
            initial_value,
            parent=top,
            extra_dismiss_text='Skip')
        askfile = lambda title, prompt, initial_value: askFile(
            title,
            prompt,
            initial_value,
            parent=top,
            extra_dismiss_text='Skip')
        try:
            project = loadProject(path=projectDir,
                                  showWarning=showWarning,
                                  askDir=askdir,
                                  askFile=askfile)
        except ApiError, e:
            showError('Reading project', e.error_msg, parent=top)
Example #6
0
    def checkAllShiftLists(self):
        """
        Return True on error
        """        
        if not self.showMessages:
#            print 'switching messaging off temporarily.'
            switchOutput(False)        
        ccpnProject = loadProject(self.ccpnDir)
        if not self.showMessages:
            print 'switching messaging on again.'
            switchOutput(True)
        if ccpnProject == None:
            nTerror("Failed to load CCPN project from: %s" % self.ccpnDir)
            return True
        
#        shiftLoL = ccpnProject.currentNmrProject.findAllMeasurementLists(className='ShiftList')
        # Use sorting by CCPN.
        shiftLoL = filterListByObjectClassName( ccpnProject.currentNmrProject.sortedMeasurementLists(), Ccpn.CCPN_CS_LIST )
#        nTdebug("Working on shiftLoL %s", str(shiftLoL))
        
        for i,shiftList in enumerate(shiftLoL):
            shiftListSerial=shiftList.serial
#            nTdebug("Working on shiftListSerial %s", shiftListSerial)
            self.checkProject(ccpnProject=ccpnProject, shiftListSerial=shiftListSerial)
            self.tagProject()
            if self.tagCingProject(shiftList, i):
                return True
Example #7
0
def launchApplication(filename=None):

    global top

    root = Tkinter.Tk()
    root.withdraw()
    top = ApplicationPopup(root)

    project = None
    if filename:
        file = normalisePath(filename)
        askdir = lambda title, prompt, initial_value, default_dir: askDir(
            title,
            prompt,
            initial_value,
            parent=top,
            extra_dismiss_text='Skip',
            default_dir=default_dir)
        askfile = lambda title, prompt, initial_value: askFile(
            title,
            prompt,
            initial_value,
            parent=top,
            extra_dismiss_text='Skip')
        try:
            project = loadProject(path=file,
                                  showWarning=showWarning,
                                  askDir=askdir,
                                  askFile=askfile)
        except ApiError, e:
            showError('Reading project', e.error_msg)
Example #8
0
    def __init__(self,
                 parent,
                 title='Project : Open',
                 callback=None,
                 help_msg='',
                 help_url='',
                 load_project=None,
                 *args,
                 **kw):

        self.callback = callback
        self.help_msg = help_msg
        self.help_url = help_url
        self.project = None

        if not load_project:

            askdir = lambda title, prompt, initial_value: askDir(
                title,
                prompt,
                initial_value,
                parent=self,
                extra_dismiss_text='Skip')
            askfile = lambda title, prompt, initial_value: askFile(
                title,
                prompt,
                initial_value,
                parent=self,
                extra_dismiss_text='Skip')
            load_project = lambda path: loadProject(
                path, showWarning=showWarning, askDir=askdir, askFile=askfile)

        self.load_project = load_project

        BasePopup.__init__(self, parent=parent, title=title, *args, **kw)
Example #9
0
def convert(projectName, inputDir, projectNameNew):
    "Testing doc strings"
    # Adjust the parameters below!
    removeOriginalStructureEnsemble = True
    addStructureEnsemble = True # From all *.pdb files in inputDir.

    ccpnPath = os.path.join(inputDir, projectName)
    ccpnProject = loadProject(ccpnPath)

    ccpnMolSystem = ccpnProject.findFirstMolSystem()
    nTmessage( 'found ccpnMolSystem: %s' % ccpnMolSystem )
#    print 'status: %s' % ccpnMolSystem.setCode(projectName) # impossible; reported to ccpn team.

    if removeOriginalStructureEnsemble:
        structureEnsemble = ccpnProject.findFirstStructureEnsemble()
        if structureEnsemble:
            nTmessage("Removing first found structureEnsemble -A-")
            structureEnsemble.delete()
        else:
            nTwarning("No structureEnsemble found; can't remove it.")

    if addStructureEnsemble:
        structureGeneration = ccpnProject.newStructureGeneration()
        guiRoot = Tkinter.Tk()
        format = PseudoPdbFormat(ccpnProject, guiRoot, verbose = 1)

        globPattern = inputDir + '/*.pdb'
        fileList = glob(globPattern)
        nTdebug("From %s will read files: %s" % (globPattern,fileList))
        format.readCoordinates(fileList, strucGen = structureGeneration, minimalPrompts = 1, linkAtoms = 0)

    nTmessage(  'saving to new path if all checks are valid' )
    # the newPath basename will be taken according to ccpn code doc.
    ccpnPathNew = os.path.join(inputDir, projectNameNew)
    saveProject(ccpnProject, checkValid=True, newPath=ccpnPathNew, removeExisting=True)
Example #10
0
    def setupProject(self, dirPath, projectName):

        self.projectDirPath = dirPath

        try:
            self.ccpnProject = loadProject(dirPath)
            print "Read existing CCPN project..."

        except:
            print "Creating new CCPN project..."

            projectName = returnMemopsWord(projectName)
            self.ccpnProject = Implementation.MemopsRoot(name=projectName)
            self.nmrProject = self.ccpnProject.newNmrProject(
                name=self.ccpnProject.name)

            if not os.path.exists(dirPath):
                os.mkdir(dirPath)

            repository = self.ccpnProject.findFirstRepository(name='userData')

            if not repository.url.path == dirPath:
                url = Implementation.Url(path=dirPath)
                repository.url = url

        # TODO: check name of project: if not same CRASH OUT!

        return self.ccpnProject
Example #11
0
    def unpackCcpnProjectTgz(self, tgzFileName, removeFile=False):
        """
    Unpack a CCPN project and read it
    """

        textOutput = self.unpackTgzFile(tgzFileName)

        lines = textOutput.split("\n")
        ccpnProjectId = lines[0]

        ccpnProject = loadProject(ccpnProjectId)

        return ccpnProject
Example #12
0
def convert(projectName, inputDir, projectNameNew):
    "Testing doc strings"
    # Adjust the parameters below!
    removeOriginalStructureEnsemble = True
    addStructureEnsemble = True  # From all *.pdb files in inputDir.

    ccpnPath = os.path.join(inputDir, projectName)
    ccpnProject = loadProject(ccpnPath)

    ccpnMolSystem = ccpnProject.findFirstMolSystem()
    nTmessage('found ccpnMolSystem: %s' % ccpnMolSystem)
    #    print 'status: %s' % ccpnMolSystem.setCode(projectName) # impossible; reported to ccpn team.

    if removeOriginalStructureEnsemble:
        structureEnsemble = ccpnProject.findFirstStructureEnsemble()
        if structureEnsemble:
            nTmessage("Removing first found structureEnsemble -A-")
            structureEnsemble.delete()
        else:
            nTwarning("No structureEnsemble found; can't remove it.")

    if addStructureEnsemble:
        structureGeneration = ccpnProject.newStructureGeneration()
        guiRoot = Tkinter.Tk()
        format = PseudoPdbFormat(ccpnProject, guiRoot, verbose=1)

        globPattern = inputDir + '/*.pdb'
        fileList = glob(globPattern)
        nTdebug("From %s will read files: %s" % (globPattern, fileList))
        format.readCoordinates(fileList,
                               strucGen=structureGeneration,
                               minimalPrompts=1,
                               linkAtoms=0)

    nTmessage('saving to new path if all checks are valid')
    # the newPath basename will be taken according to ccpn code doc.
    ccpnPathNew = os.path.join(inputDir, projectNameNew)
    saveProject(ccpnProject,
                checkValid=True,
                newPath=ccpnPathNew,
                removeExisting=True)
Example #13
0
    def loadProject(self):

        # This is the directory where the original CCPN project lives
        origCcpnProjectDir = os.path.join(self.projectDirectory, self.idCode)
        
        # This is the zipped CCPN project location
        zippedCcpnProject = os.path.join(origCcpnProjectDir, 'linkNmrStarData.zip')
        
        # Unzip into the original CCPN project directory
        try:
            curTarFile = tarfile.open(zippedCcpnProject, 'r:gz')
            curTarFile.extractall(origCcpnProjectDir)
        except Exception:
            curZipFile = zipfile.ZipFile(zippedCcpnProject)
            curZipFile.extractall(origCcpnProjectDir)

        
        self.ccpnProjectDir =  os.path.join(origCcpnProjectDir, 'linkNmrStarData')
        
        assert os.path.exists(self.ccpnProjectDir), 'Project did not unzip correctly'
        
        self.ccpnProject = loadProject(self.ccpnProjectDir)
Example #14
0
    def loadProject(self):

        # This is the directory where the original CCPN project lives
        origCcpnProjectDir = os.path.join(self.projectDirectory, self.idCode)

        # This is the zipped CCPN project location
        zippedCcpnProject = os.path.join(origCcpnProjectDir,
                                         'linkNmrStarData.zip')

        # Unzip into the original CCPN project directory
        try:
            curTarFile = tarfile.open(zippedCcpnProject, 'r:gz')
            curTarFile.extractall(origCcpnProjectDir)
        except Exception:
            curZipFile = zipfile.ZipFile(zippedCcpnProject)
            curZipFile.extractall(origCcpnProjectDir)

        self.ccpnProjectDir = os.path.join(origCcpnProjectDir,
                                           'linkNmrStarData')

        assert os.path.exists(
            self.ccpnProjectDir), 'Project did not unzip correctly'

        self.ccpnProject = loadProject(self.ccpnProjectDir)
Example #15
0
    return finalInfoList2


def listCol6Cmp(x, y):
    return cmp(x[5], y[5])


if __name__ == '__main__':

    argv = sys.argv[:]
    argc = len(argv)

    mr = None

    if argc > 1:
        projectDir = argv[1]
        mr = loadProject(projectDir)
    else:
        projectDir = None

    nmrEntry = mr.currentNmrEntryStore.findFirstEntry()

    if nmrEntry:

        finalInfoList = checkNmrEntryCompleteness(nmrEntry)

        #print finalInfoList

        for row in finalInfoList:
            print row  #[0], row[3:]
Example #16
0
    def process(self):
        
        rootProject = loadProject(self._projectDir)

        rootProject.saveModified()
Example #17
0
        print 'must specify project directory'
        sys.exit()

    path = sys.argv[1]

    import Tkinter
    from memops.gui.DataEntry import askDir, askFile
    from memops.gui.MessageReporter import showWarning
    from memops.general.Io import loadProject
    from memops.universal.Io import normalisePath

    # This needs to be above loadProject because that can pop up
    # dialogs, and it will create a root if one has not been created
    # already, and that will lead to the later code crashing
    r = Tkinter.Tk()

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

    popup = DataLocationPopup(r, project)

    r.withdraw()
    r.mainloop()
Example #18
0
from memops.universal.Io import joinPath

###################
# Main of program #
###################

if __name__ == "__main__":

  #
  # Load a CCPN project
  #
  
  projectName = 'test'
  projectDir = os.path.join(os.getcwd(),'local',projectName)

  ccpnProject = loadProject(projectDir,projectName)

  #
  # Because the original project was saved in a different directory structure,
  # the paths have to be reset first... here I am resetting everything 'hardcoded'
  # based on the examples and/or data directory.
  #

  localDataPaths = {}
  localDataPaths['examples'] = os.path.abspath('.')
  localDataPaths['data'] = joinPath(getTopDirectory(),'data')

  for repository in ccpnProject.repositories:
    for findName in ('examples','data'):
      findNameIndex = repository.url.path.find(findName)
      if  findNameIndex>= 0:
Example #19
0
def convert(projectName,
            inputDir,
            outputFile,
            excludeSaveFrames=('general_distance_constraints', )):

    print "projectName: %s" % projectName
    print "inputDir: %s" % inputDir
    print "outputFile: %s" % outputFile
    print "excludeSaveFrames: %s" % excludeSaveFrames
    ccpnPath = os.path.join(inputDir, projectName)
    ccpnProject = loadProject(ccpnPath)

    # Try to find the CING setup info in the project.
    cingCalcStore = ccpnProject.findFirstNmrCalcStore(name='CING')
    if cingCalcStore is not None:
        nmrProject = cingCalcStore.nmrProject

        run = cingCalcStore.findFirstRun(status='pending')
        nmrConstraintStore = run.findFirstData(
            className='ConstraintStoreData').nmrConstraintStore
        molSystem = (
            run.findFirstData(className='MolSystemData') or run.findFirstData(
                className='StructureEnsembleData').structureEnsemble
            or run.findFirstData(
                className='MolResidueData').findFirstChain()).molSystem
        nmrEntryStore = (
            ccpnProject.findFirstNmrEntryStore(name='newNmrEntryStoreName')
            or ccpnProject.newNmrEntryStore(name='newNmrEntryStoreName'))

        nmrEntry = nmrEntryStore.newEntry(molSystem=molSystem,
                                          name='newNmrEntryName')
        structureGeneration = nmrProject.newStructureGeneration(
            name='newNmrStructureGeneration',
            nmrConstraintStore=nmrConstraintStore)
        nmrEntry.addStructureGeneration(structureGeneration)

        nmrEntry.measurementLists = [
            x.measurementList
            for x in run.findAllData(className='MeasurementListData')
        ]
        nmrEntry.structureAnalyses = nmrProject.sortedStructureAnalyses()
        nmrEntry.peakLists = [
            x.peakList for x in run.findAllData(className='PeakListData')
        ]

        structureGeneration.structureEnsemble = run.findFirstData(
            className='StructureEnsembleData').structureEnsemble
    else:
        nmrEntryStore = ccpnProject.newNmrEntryStore(
            name="newNmrEntryStoreName")
        molSystem = ccpnProject.findFirstMolSystem()
        nmrEntry = nmrEntryStore.newEntry(molSystem=molSystem,
                                          name='newNmrEntryName')

        nmrProject = ccpnProject.currentNmrProject
        #
        # nmrEntry.structureGenerations = nmrProject.sortedStructureGenerations()
        # if nmrEntry.structureGenerations:
        #     print "Using structureGenerations from nmrProject"
        structureGenerations = nmrProject.sortedStructureGenerations()

        if structureGenerations:
            # NBNB RHF October 2014. WATTOS breaks if there is more than one structureGeneration
            # Add the newest ony, and let the pre-existing code take care of ensembles
            nmrEntry.addStructureGeneration(structureGenerations[-1])
        else:
            ncs = ccpnProject.findFirstNmrConstraintStore()
            sG = None
            if not ncs:
                print "Failed to find any NmrConstraintStore from project"
            else:
                sG = ncs.findFirstStructureGeneration()
            if sG:
                nmrEntry.addStructureGeneration(sG)
                print "Using structureGenerations from nmrProject"
            else:
                print "Failed to find nmrEntry.structureGenerations from nmrProject or nmrConstraintStore; creating a new one."
                strucGen = nmrProject.newStructureGeneration()
                nmrEntry.addStructureGeneration(strucGen)
            # end if
            # end if
        # end if

        try:  # ccpn stable as 08 Jul 2009
            nmrEntry.structureAnalyses = nmrProject.sortedStructureAnalysiss(
            )  # watch out for misspelling.
        except AttributeError:  # ccpn trunk fixed misspelled function
            nmrEntry.structureAnalyses = nmrProject.sortedStructureAnalyses()
        if not nmrEntry.structureAnalyses:
            print "Failed to find nmrEntry.structureAnalyses"
        nmrEntry.measurementLists = nmrProject.sortedMeasurementLists()
        if not nmrEntry.measurementLists:
            print "Failed to find nmrEntry.measurementLists"

        # TJR, RHF 16 Oct 2014
        # DIfferent hack. We now have only ever allow 1 (ONE) structureGeneration.
        assert len(nmrEntry.root.sortedStructureEnsembles()
                   ) == 1, "Must have one and only one ensemble"
        assert len(nmrProject.sortedNmrConstraintStores()
                   ) == 1, "Must have one and only one set of constraints"

        #
        #  Hack to hook up coordinates, hopefully correctly (Wim 30/04/2009)
        #    if nmrEntry.structureGenerations:
        #       hasStructureEnsemble = False
        #       for strucGen in nmrEntry.structureGenerations:
        #           if strucGen.structureEnsemble:
        #               hasStructureEnsemble = True
        #               break
        #           # end if
        #       # end for
        #
        #       print "hasStructureEnsemble: %s" % hasStructureEnsemble
        #       # This will only work dependably if there is one structureGeneration, one structureEnsemble...
        #       # Take the one that was created last in any case, fingers crossed that they match up!
        #       if not hasStructureEnsemble and ccpnProject.structureEnsembles:
        #           nmrEntry.sortedStructureGenerations()[-1].structureEnsemble = ccpnProject.sortedStructureEnsembles()[-1]
        #       # end if
        #    # end if

        for ne in nmrProject.sortedExperiments(
        ):  # will be sortedNmrExperiments
            for ds in ne.sortedDataSources():
                for pl in ds.sortedPeakLists():
                    nmrEntry.addPeakList(pl)

    nmrStarExport = NmrStarExport(nmrEntry,
                                  nmrStarVersion='3.1',
                                  forceEntryId='1')
    nmrStarExport.createFile(outputFile,
                             excludeSaveFrames=excludeSaveFrames,
                             verbose=True)

    # Set the header comment - only set this if you need a standard header!
    topComment = "# File written for CING by NmrStarExport.py code"
    nmrStarExport.writeFile(title="CING", topComment=topComment, verbose=True)
Example #20
0
    def initialiseWorkflow(
        self,
        ccpnProject=None,  # One of these top three is obligatory!
        ccpnProjectTgz=None,
        identifier=None,
        useGui=False,
        overwrite=True,
        initializeObjects=True,  # Set to False if don't want to automatically set NmrProject and constraint stuff. Should probably do this differently anyway! More options...
        verbose=True):

        self.verbose = verbose

        #
        # Need either an existing CCPN project or an identifier for it - note that this
        # can be set as part of the class if required.
        #

        if not hasattr(self, 'identifier') and identifier:
            self.identifier = identifier

        if not ccpnProject and not self.identifier and not ccpnProjectTgz:
            raise self.WorkFlowError(
                "No CCPN project or identifier given - aborting workflow.")

        #
        # Set day/time when workflow was run
        #

        self.timeFlag = self.getTimeString()

        #
        # Set CCPN project - this is obligatory, and the CCPN project is unpacked if
        # tgz file. Is this smart? Should I always start from a loaded project?
        # And always pack it (temporary file) if have to send off? Probably best!
        #

        self.ccpnProject = None

        if ccpnProject:
            self.ccpnProject = ccpnProject
        elif ccpnProjectTgz:
            self.ccpnProject = self.unpackCcpnProjectTgz(ccpnProjectTgz)
        else:

            try:
                tmpCcpnProject = loadProject(self.identifier)
            except:
                tmpCcpnProject = None

            if tmpCcpnProject:
                if not overwrite:
                    print("  Warning: using existing project!")
                    self.ccpnProject = tmpCcpnProject
                else:
                    print("  Warning: overwriting existing project!")
                    shutil.rmtree(self.identifier)

            if not self.ccpnProject:
                self.ccpnProject = Implementation.MemopsRoot(
                    name=self.identifier)

        #
        # Set other CCPN objects (if required)
        #

        if initializeObjects:
            # NMR project
            setCurrentStore(self.ccpnProject, 'NmrProject')
            self.nmrProject = self.ccpnProject.currentNmrProject

            nmrConstraintStores = self.ccpnProject.sortedNmrConstraintStores()
            if not nmrConstraintStores:
                self.nmrConstraintStore = None
            else:
                if len(nmrConstraintStores) > 1:
                    raise self.WorkFlowError(
                        "Only one NMR constraint store allowed for running workflow. Please modify input."
                    )
                self.nmrConstraintStore = nmrConstraintStores[0]

        # TODO nmrEntry?

        #
        # Set graphical interface, if required
        #

        self.useGui = useGui
        if useGui:
            import Tkinter
            self.guiRoot = Tkinter.Tk()
        else:
            self.guiRoot = None

        #
        # Run other <programShortCode>__init__
        #

        for program in programList:
            programInit = '%s__init__' % program.lower()

            if hasattr(self, programInit):
                getattr(self, programInit)()
Example #21
0
import os

# Import the loadProject() function.

from memops.general.Io import loadProject
from memops.universal import Io as uniIo

# Import the Url class.

from memops.api.Implementation import Url

if __name__ == '__main__':

    # Load the old project - need to specify the correct directory name.

    project = loadProject('topObjectTest')

    print 'Project: [%s]\n' % project

    # Find the right repository that contains the project data.

    projectRepos = project.findFirstRepository(name='userData')

    # Specify a new location to save the project in.

    newPath = uniIo.normalisePath(
        os.path.join(os.path.abspath('.'), 'newDir', 'newSubDir'))

    # Make a new Url pointing to the new location and link it to the
    # 'userData' repository.
Example #22
0
    def test_ccpn(self):
        #        cing.verbosity = verbosityDebug
        #        if you have a local copy you can use it; make sure to adjust the path setting below.
        fastestTest = True  # DEFAULT: True. Not passed to the validate routine in order to customize checks for speed.

        modelCount = 99  # DEFAULT: 99
        redoFromCingProject = False  # DEFAULT: False
        htmlOnly = False  # DEFAULT: False # default is False but enable it for faster runs without some actual data.
        doWhatif = True  # DEFAULT: True # disables whatif actual run
        doProcheck = True  # DEFAULT: True
        doWattos = True  # DEFAULT: True
        doQueeny = True  # DEFAULT: True
        doTalos = True  # DEFAULT: True
        filterVasco = True  # DEFAULT: True
        filterTopViolations = True  # DEFAULT: True
        useNrgArchive = False  # DEFAULT: False
        ranges = CV_STR  # DEFAULT: CV_STR
        #        ranges='173-177'
        #        ranges='6-13,29-45' # 1bus

        doSwapCheck = False
        doRestoreCheck = False
        doStoreCheck = False  # DEFAULT: False Requires sqlAlchemy
        doSave = not redoFromCingProject  # DEFAULT: False Requires sqlAlchemy

        if fastestTest:
            modelCount = 2  # DEFAULT 2
            #            redoFromCingProject = False
            htmlOnly = True  # DEFAULT: True
            doWhatif = False  # DEFAULT: False
            doProcheck = False  # DEFAULT: False
            doWattos = False  # DEFAULT: False
            doQueeny = False  # DEFAULT: False
            doTalos = False  # DEFAULT: False
            filterVasco = False  # DEFAULT: False
            doRestoreCheck = False  # DEFAULT: False
            doStoreCheck = False  # DEFAULT: False
        if redoFromCingProject:
            useNrgArchive = False
            doWhatif = False
            doProcheck = False
            doWattos = False
            doTalos = False
        cingDirTmpTest = os.path.join(cingDirTmp, getCallerName())
        mkdirs(cingDirTmpTest)
        self.failIf(os.chdir(cingDirTmpTest),
                    msg="Failed to change to test directory for files: " +
                    cingDirTmpTest)
        for i, entryId in enumerate(AllChecks.entryList):

            if i:
                nTmessage('\n\n')
            if redoFromCingProject:
                project = Project.open(entryId, status='old')
            else:
                project = Project.open(entryId, status='new')
                self.assertTrue(project, 'Failed opening project: ' + entryId)

                if useNrgArchive:  # default is False
                    #                inputArchiveDir = os.path.join('/Library/WebServer/Documents/NRG-CING/recoordSync', entryId)
                    # Mounted from nmr.cmbi.ru.nl
                    #                inputArchiveDir = os.path.join('/Volumes/tria1/Library/WebServer/Documents/NRG-CING/recoordSync', entryId)
                    inputArchiveDir = os.path.join(
                        '/Users/jd/ccpn_tmp/data/recoord', entryId)
                else:
                    inputArchiveDir = os.path.join(cingDirTestsData, "ccpn")

                ccpnFile = os.path.join(inputArchiveDir, entryId + ".tgz")
                if not os.path.exists(ccpnFile):
                    ccpnFile = os.path.join(inputArchiveDir,
                                            entryId + ".tar.gz")
                    if not os.path.exists(ccpnFile):
                        self.fail("Neither %s or the .tgz exist" % ccpnFile)

                if doSwapCheck:  # Need to start with ccpn without loading into CING api yet.
                    if os.path.exists(entryId):
                        nTmessage("Removing previous directory: %s" % entryId)
                        rmtree(entryId)
                    do_cmd("tar -xzf " +
                           ccpnFile)  # will extract to local dir.
                    if os.path.exists('linkNmrStarData'):
                        nTmessage(
                            "Renaming standard directory linkNmrStarData to entry: %s"
                            % entryId)
                        os.rename('linkNmrStarData', entryId)

                    ccpnProject = loadProject(entryId)
                    if not ccpnProject:
                        self.fail("Failed to read project: %s" % entryId)
            #        constraintsHandler = ConstraintsHandler()
                    nmrConstraintStore = ccpnProject.findFirstNmrConstraintStore(
                    )
                    structureEnsemble = ccpnProject.findFirstStructureEnsemble(
                    )
                    numSwapCheckRuns = 2
                    if nmrConstraintStore:
                        if structureEnsemble:
                            swapCheck(nmrConstraintStore, structureEnsemble,
                                      numSwapCheckRuns)
                        else:
                            nTmessage(
                                "Failed to find structureEnsemble; skipping swapCheck"
                            )
                    else:
                        nTmessage(
                            "Failed to find nmrConstraintStore; skipping swapCheck"
                        )
            #        constraintsHandler.swapCheck(nmrConstraintStore, structureEnsemble, numSwapCheckRuns)
                    nTmessage('Saving to new path')
                    #        checkValid=True,
                    saveProject(ccpnProject,
                                newPath=entryId,
                                removeExisting=True)
                    ccpnFile = entryId  # set to local dir now.
                # end if doSwapCheck
                self.assertTrue(
                    project.initCcpn(ccpnFolder=ccpnFile,
                                     modelCount=modelCount))
#                if doSave:
#                    self.assertTrue(project.save())

            if False:
                ranges = "173-183"
#                residueOfInterest = range(171,174)
#                for residue in project.molecule.A.allResidues():
#                    if residue.resNum not in residueOfInterest:
#    #                    nTmessage("Removing residue of no interest")
#                        project.molecule.A.removeResidue(residue)
            if False:
                ccpnProject = project.ccpn
                printSequenceFromCcpnProject(ccpnProject)

            if True:
                self.assertFalse(project.molecule.setRanges(ranges))
                nTdebug('In test_ccpn.py: ranges: %s' %
                        str(project.molecule.ranges))
                project.molecule.rangesToMmCifRanges(ranges)

            if True:
                self.assertFalse(
                    project.validate(
                        htmlOnly=htmlOnly,
                        ranges=ranges,
                        #                                              fastestTest=fastestTest, # disabled
                        doProcheck=doProcheck,
                        doWhatif=doWhatif,
                        doWattos=doWattos,
                        doQueeny=doQueeny,
                        doTalos=doTalos,
                        filterVasco=filterVasco,
                        filterTopViolations=filterTopViolations))
                if doWattos and False:
                    mol = project.molecule
                    completenessMol = mol.getDeepByKeys(
                        WATTOS_STR, COMPLCHK_STR, VALUE_LIST_STR)
                    nTdebug("completenessMol: %s" % completenessMol)
                    for res in mol.allResidues():
                        completenessRes = res.getDeepByKeys(
                            WATTOS_STR, COMPLCHK_STR, VALUE_LIST_STR)
                        nTdebug("%s: %s" % (res, completenessRes))
                    # end for
                # end if
                color = project.molecule.getRogColor()
                nTdebug("The color of this molecule is: %s" % color)
                self.assertFalse(color == COLOR_RED)  # ;-)
            # end if
#            self.assertTrue(project.exportValidation2ccpn())
#            self.assertFalse(project.removeCcpnReferences())
# Do not leave the old CCPN directory laying around since it might get added to by another test.
#            if os.path.exists(entryId):
#                self.assertFalse(shutil.rmtree(entryId))

            if False:
                self.assertTrue(project.save())
                self.assertTrue(project.saveCcpn(entryId))

            if doRestoreCheck:
                del project
                project = Project.open(entryId, status='old')
                self.assertTrue(project,
                                'Failed reopening project: ' + entryId)
            if doStoreCheck:
                #                # Does require below import which is used here to trigger import warning in case it's not installed.
                # pylint: disable=W0612
                from cing.PluginCode.sqlAlchemy import CsqlAlchemy  #@UnusedImport # pylint: disable=W0404
                if doStoreCING2db(entryId, ARCHIVE_NRG_ID, project=project):
                    nTerror(
                        "Failed to store CING project's data to DB but continuing."
                    )
            if doSave:
                self.assertTrue(project.save())
Example #23
0
def fcProcessEntry( entry_code, ccpnTgzFile, outputCcpnTgzFile, functionToRun='swapCheck'):
    """
    E.g.

    entry_code          1brv
    ccpnTgzFile         /NRG-CING/prep/S/br/1brv/1brv.tgz Full path
    outputCcpnTgzFile   1brv_assign.tgz but inside the project will still be keyed and named 1brv.

    Return True on error
    Can be extended later on to run a different function.
    Will run in cwd.
    """

    # Adjust the parameters below
    isInteractive = False
    doSwapCheck = True
    doSaveProject = True
    doExport = True

    minimalPrompts = True
    verbose = True
    allowPopups = False

    if isInteractive:
        allowPopups = True
        minimalPrompts = False

    print 'entry_code                                                                                    ', entry_code
#    print 'bmrb_id                                                                                       ', bmrb_id
    print 'allowPopups                                                                                   ', allowPopups
    print 'isInteractive                                                                                 ', isInteractive
    print 'minimalPrompts                                                                                ', minimalPrompts
    print 'verbose                                                                                       ', verbose
    print 'doSwapCheck                                                                                   ', doSwapCheck
    print 'doSaveProject                                                                                 ', doSaveProject
    print 'doExport                                                                                      ', doExport

    guiRoot = None
    if allowPopups:
        guiRoot = Tkinter.Tk()

    if not os.path.exists(ccpnTgzFile):
        nTerror("Input file not found: %s" % ccpnTgzFile)
        return True
    nTdebug("Looking at %s" % entry_code)

    if os.path.exists(entry_code):
        nTmessage("Removing previous directory: %s" % entry_code)
        rmtree(entry_code)
    do_cmd("tar -xzf " + ccpnTgzFile) # will unpack to cwd.
    if os.path.exists('linkNmrStarData'):
        nTmessage("Renaming standard directory linkNmrStarData to entry: %s" % entry_code)
        os.rename('linkNmrStarData', entry_code)

    ccpnProject = loadProject(entry_code)
    if not ccpnProject:
        nTerror("Failed to read project: %s" % entry_code)
        return True

    if doSwapCheck:
#        constraintsHandler = ConstraintsHandler()
        nmrConstraintStore = ccpnProject.findFirstNmrConstraintStore()
        structureEnsemble = ccpnProject.findFirstStructureEnsemble()
        if nmrConstraintStore:
            if structureEnsemble:
                swapCheck(nmrConstraintStore, structureEnsemble)
            else:
                nTmessage("Failed to find structureEnsemble; skipping swapCheck")
        else:
            nTmessage("Failed to find nmrConstraintStore; skipping swapCheck")
#        constraintsHandler.swapCheck(nmrConstraintStore, structureEnsemble, numSwapCheckRuns)
    # end if doSwapCheck

    if doSaveProject:
        nTmessage('Saving to new path: %s' % entry_code)
        saveProject(ccpnProject, newPath=entry_code, removeExisting=True)
    if doExport:
        if os.path.exists(outputCcpnTgzFile):
            nTmessage("Overwriting: " + outputCcpnTgzFile)
        myTar = tarfile.open(outputCcpnTgzFile, mode='w:gz') # overwrites
        myTar.add(entry_code)
        myTar.close()
    if guiRoot:
        guiRoot.destroy()
Example #24
0
      residue = chain.newResidue(seqId=seqId, seqCode=molSysResidue.seqCode)

      # create MolStructure.Atoms
      for molSysAtom in molSysResidue.atoms:
        chemAtom = molSysAtom.chemAtom
        if chemAtom.elementSymbol != 'H':
          atom = residue.newAtom(name=molSysAtom.name)

          # create MolStructure.Coord
          coord = atom.newCoord(model=model)
          coord.x = random.random()
          coord.y = random.random()
          coord.z = random.random()

  #root.saveModified()

if __name__ == '__main__':

  import sys

  if len(sys.argv) == 1:
    from memops.api.Implementation import MemopsRoot
    root = MemopsRoot(name='testNmr')
  elif len(sys.argv) == 2:
    from memops.general.Io import loadProject
    repositoryPath = sys.argv[1]
    root = loadProject(path=repositoryPath)

  main(root)

Example #25
0
def replaceCoordinates():

    cityList = [
        'Cheshire', 'Frankfurt', 'Lyon', 'Paris', 'Piscataway', 'Seattle',
        'Utrecht'
    ]
    maxCities = 1
    maxEntries = 1
    # Adjust the parameters below!
    removeOriginalStructureEnsemble = True
    addStructureEnsemble = True  # From all *.pdb files in inputDir.

    dataOrgDir = os.path.join(baseDir, DATA_STR)
    dataDividedDir = os.path.join(baseDir, DATA_STR)
    #        _scriptName = sys.argv[0]
    # parameters for doScriptOnEntryList
    startDir = '/Library/WebServer/Documents/' + CASD_NMR_BASE_NAME
    entryListFileName = os.path.join(startDir, 'list', 'entry_list_todo.csv')
    entryList = readLinesFromFile(entryListFileName)  #@UnusedVariable
    entryList = ['ET109Aox']

    for entryCode in entryList[0:maxEntries]:
        ch23 = entryCode[1:3]
        dataOrgEntryDir = os.path.join(dataOrgDir, entryCode)
        ccpnFile = os.path.join(dataOrgEntryDir, entryCode + ".tgz")
        for city in cityList[0:maxCities]:
            entryCodeNew = entryCode + city
            dataDividedXDir = os.path.join(dataDividedDir, ch23)
            inputAuthorDir = os.path.join(dataDividedXDir, entryCodeNew,
                                          'Author')
            outputNijmegenDir = os.path.join(dataDividedXDir, entryCodeNew,
                                             'Nijmegen')

            globPattern = inputAuthorDir + '/*.pdb'
            pdbFileList = glob(globPattern)
            if not pdbFileList:
                nTmessage("Skipping because there is no PDB file in: " +
                          os.getcwd())
                continue

            if not os.path.exists(inputAuthorDir):
                mkdirs(inputAuthorDir)
            if not os.path.exists(outputNijmegenDir):
                mkdirs(outputNijmegenDir)

            os.chdir(outputNijmegenDir)
            if False:
                # By reading the ccpn tgz into cing it is also untarred/tested.
                project = Project.open(entryCode, status='new')
                project.initCcpn(ccpnFolder=ccpnFile, modelCount=1)
                project.removeFromDisk()
                project.close(save=False)

            if True:
                ccpnProject = loadProject(entryCode)
                nmrProject = ccpnProject.currentNmrProject
                ccpnMolSystem = ccpnProject.findFirstMolSystem()
                nTmessage('found ccpnMolSystem: %s' % ccpnMolSystem)
                #    print 'status: %s' % ccpnMolSystem.setCode(projectName) # impossible; reported to ccpn team.

                if removeOriginalStructureEnsemble:
                    structureEnsemble = ccpnProject.findFirstStructureEnsemble(
                    )
                    if structureEnsemble:
                        nTmessage("Removing first found structureEnsemble")
                        structureEnsemble.delete()
                    else:
                        nTwarning(
                            "No structureEnsemble found; can't remove it.")

                if addStructureEnsemble:
                    structureGeneration = nmrProject.newStructureGeneration()
                    fileList = None
                    nTdebug("From %s will read files: %s" %
                            (globPattern, fileList))
                    guiRoot = Tkinter.Tk()
                    format = PseudoPdbFormat(ccpnProject, guiRoot, verbose=1)
                    format.readCoordinates(fileList,
                                           strucGen=structureGeneration,
                                           minimalPrompts=1,
                                           linkAtoms=0)

                nTmessage('saving to new path if all checks are valid')
                # the newPath basename will be taken according to ccpn code doc.
                saveProject(ccpnProject,
                            checkValid=True,
                            newPath=entryCodeNew,
                            removeExisting=True)
Example #26
0
#
# - Print out the residue type, position and all the atoms found in
#     each residue.
#
# - Check that the project is valid.
#
# - Hint: Look at class methods for MemopsRoot objects.
#

from memops.general.Io import loadProject

if __name__ == '__main__':

  # Load the project with the DNA molecule.

  project = loadProject('dnaTest')

  # Locate the DNA molecule in the project.

  molecule = project.findFirstMolecule(name = 'myDnaMoleculeName')

  # Make a new molSystem top object.

  keywds = {'code': 'myMolecularSystemCode',
            'name': 'My molecular system name'}
  molSystem = project.newMolSystem(**keywds)

  # Make a chain for this molSystem that is linked to the reference
  #   DNA molecule.

  chain = molSystem.newChain(code = 'A', molecule = molecule)
Example #27
0
    ccpnProjectDir, ariaProjectPath = cmdArgs[:2]

    workingDir = None
    tempDir = None

    if nArgs > 2:
        workingDir = cmdArgs[2]
    if nArgs > 3:
        tempDir = cmdArgs[3]

    from memops.general.Io import loadProject

    if not os.path.exists(ccpnProjectDir):
        raise Exception(FAIL + 'CCPN project directory does not exist')

    if not os.path.isdir(ccpnProjectDir):
        raise Exception(FAIL + 'CCPN project location is not a directory')

    try:
        ccpnProject = loadProject(ccpnProjectDir)
    except Exception, err:
        raise Exception(FAIL + 'CCPN project failed to load. original error:' +
                        err)

    makeAriaProject(ccpnProject,
                    ariaProjectPath,
                    workingDir=workingDir,
                    tempDir=tempDir)

    print 'Done. Saved ARIA project to: %s' % ariaProjectPath
Example #28
0
def convert(projectName, inputDir, outputFile, excludeSaveFrames = ('general_distance_constraints',) ):

    print "projectName: %s" % projectName
    print "inputDir: %s" % inputDir
    print "outputFile: %s" % outputFile
    print "excludeSaveFrames: %s" % excludeSaveFrames
    ccpnPath = os.path.join(inputDir, projectName)
    ccpnProject = loadProject(ccpnPath)

    # Try to find the CING setup info in the project.
    cingCalcStore = ccpnProject.findFirstNmrCalcStore(name='CING')
    if cingCalcStore is not None:
        nmrProject = cingCalcStore.nmrProject

        run = cingCalcStore.findFirstRun(status='pending')
        nmrConstraintStore = run.findFirstData(className='ConstraintStoreData').nmrConstraintStore
        molSystem = (run.findFirstData(className='MolSystemData') or
                     run.findFirstData(className='StructureEnsembleData').structureEnsemble or
                     run.findFirstData(className='MolResidueData').findFirstChain()).molSystem
        nmrEntryStore = (ccpnProject.findFirstNmrEntryStore(name='newNmrEntryStoreName') or
                               ccpnProject.newNmrEntryStore(name='newNmrEntryStoreName'))

        nmrEntry = nmrEntryStore.newEntry(molSystem=molSystem, name='newNmrEntryName')
        structureGeneration = nmrProject.newStructureGeneration(name='newNmrStructureGeneration',
                                                                nmrConstraintStore=nmrConstraintStore)
        nmrEntry.addStructureGeneration(structureGeneration)

        nmrEntry.measurementLists = [x.measurementList for x in run.findAllData(className='MeasurementListData')]
        nmrEntry.structureAnalyses = nmrProject.sortedStructureAnalyses()
        nmrEntry.peakLists = [x.peakList for x in run.findAllData(className='PeakListData')]

        structureGeneration.structureEnsemble = run.findFirstData(className='StructureEnsembleData').structureEnsemble
    else:
        nmrEntryStore = ccpnProject.newNmrEntryStore(name = "newNmrEntryStoreName")
        molSystem = ccpnProject.findFirstMolSystem()
        nmrEntry = nmrEntryStore.newEntry( molSystem = molSystem, name = 'newNmrEntryName')

        nmrProject = ccpnProject.currentNmrProject
        #
        # nmrEntry.structureGenerations = nmrProject.sortedStructureGenerations()
        # if nmrEntry.structureGenerations:
        #     print "Using structureGenerations from nmrProject"
        structureGenerations = nmrProject.sortedStructureGenerations()

        if structureGenerations:
            # NBNB RHF October 2014. WATTOS breaks if there is more than one structureGeneration
            # Add the newest ony, and let the pre-existing code take care of ensembles
            nmrEntry.addStructureGeneration(structureGenerations[-1])
        else:
           ncs = ccpnProject.findFirstNmrConstraintStore()
           sG = None
           if not ncs:
               print "Failed to find any NmrConstraintStore from project"
           else:
               sG = ncs.findFirstStructureGeneration()
           if sG:
               nmrEntry.addStructureGeneration( sG )
               print "Using structureGenerations from nmrProject"
           else:
               print "Failed to find nmrEntry.structureGenerations from nmrProject or nmrConstraintStore; creating a new one."
               strucGen = nmrProject.newStructureGeneration()
               nmrEntry.addStructureGeneration(strucGen)
           # end if
           # end if
        # end if

        try: # ccpn stable as 08 Jul 2009
           nmrEntry.structureAnalyses = nmrProject.sortedStructureAnalysiss() # watch out for misspelling.
        except AttributeError: # ccpn trunk fixed misspelled function
           nmrEntry.structureAnalyses = nmrProject.sortedStructureAnalyses()
        if not nmrEntry.structureAnalyses:
           print "Failed to find nmrEntry.structureAnalyses"
        nmrEntry.measurementLists = nmrProject.sortedMeasurementLists()
        if not nmrEntry.measurementLists:
           print "Failed to find nmrEntry.measurementLists"


        # TJR, RHF 16 Oct 2014
        # DIfferent hack. We now have only ever allow 1 (ONE) structureGeneration.
        assert len(nmrEntry.root.sortedStructureEnsembles()) == 1, "Must have one and only one ensemble"
        assert len(nmrProject.sortedNmrConstraintStores()) == 1, "Must have one and only one set of constraints"

        #
        #  Hack to hook up coordinates, hopefully correctly (Wim 30/04/2009)
        #    if nmrEntry.structureGenerations:
        #       hasStructureEnsemble = False
        #       for strucGen in nmrEntry.structureGenerations:
        #           if strucGen.structureEnsemble:
        #               hasStructureEnsemble = True
        #               break
        #           # end if
        #       # end for
        #
        #       print "hasStructureEnsemble: %s" % hasStructureEnsemble
        #       # This will only work dependably if there is one structureGeneration, one structureEnsemble...
        #       # Take the one that was created last in any case, fingers crossed that they match up!
        #       if not hasStructureEnsemble and ccpnProject.structureEnsembles:
        #           nmrEntry.sortedStructureGenerations()[-1].structureEnsemble = ccpnProject.sortedStructureEnsembles()[-1]
        #       # end if
        #    # end if

        for ne in nmrProject.sortedExperiments(): # will be sortedNmrExperiments
           for ds in ne.sortedDataSources():
               for pl in ds.sortedPeakLists():
                   nmrEntry.addPeakList(pl)

    nmrStarExport = NmrStarExport(nmrEntry, nmrStarVersion = '3.1', forceEntryId = '1')
    nmrStarExport.createFile(outputFile, excludeSaveFrames= excludeSaveFrames, verbose = True)

    # Set the header comment - only set this if you need a standard header!
    topComment = "# File written for CING by NmrStarExport.py code"
    nmrStarExport.writeFile(title = "CING", topComment=topComment, verbose = True)
Example #29
0
    def test_ccpn(self):
#        cing.verbosity = verbosityDebug
#        if you have a local copy you can use it; make sure to adjust the path setting below.
        fastestTest = True             # DEFAULT: True. Not passed to the validate routine in order to customize checks for speed.

        modelCount=99                  # DEFAULT: 99 
        redoFromCingProject = False    # DEFAULT: False 
        htmlOnly = False               # DEFAULT: False # default is False but enable it for faster runs without some actual data.
        doWhatif = True                # DEFAULT: True # disables whatif actual run
        doProcheck = True              # DEFAULT: True 
        doWattos = True                # DEFAULT: True 
        doQueeny = True                # DEFAULT: True 
        doTalos = True                 # DEFAULT: True 
        filterVasco = True             # DEFAULT: True 
        filterTopViolations = True     # DEFAULT: True 
        useNrgArchive = False          # DEFAULT: False 
        ranges = CV_STR                # DEFAULT: CV_STR 
#        ranges='173-177'
#        ranges='6-13,29-45' # 1bus

        doSwapCheck = False
        doRestoreCheck = False
        doStoreCheck = False # DEFAULT: False Requires sqlAlchemy
        doSave = not redoFromCingProject  # DEFAULT: False Requires sqlAlchemy

        if fastestTest:
            modelCount=2 # DEFAULT 2
#            redoFromCingProject = False
            htmlOnly = True            # DEFAULT: True
            doWhatif = False           # DEFAULT: False
            doProcheck = False         # DEFAULT: False
            doWattos = False           # DEFAULT: False
            doQueeny = False           # DEFAULT: False
            doTalos = False            # DEFAULT: False
            filterVasco = False        # DEFAULT: False
            doRestoreCheck = False     # DEFAULT: False
            doStoreCheck = False       # DEFAULT: False
        if redoFromCingProject:
            useNrgArchive = False
            doWhatif = False
            doProcheck = False
            doWattos = False
            doTalos = False
        cingDirTmpTest = os.path.join( cingDirTmp, getCallerName() )
        mkdirs( cingDirTmpTest )
        self.failIf(os.chdir(cingDirTmpTest), msg =
            "Failed to change to test directory for files: " + cingDirTmpTest)
        for i,entryId in enumerate(AllChecks.entryList):

            if i:
                nTmessage('\n\n')
            if redoFromCingProject:
                project = Project.open(entryId, status = 'old')
            else:
                project = Project.open(entryId, status = 'new')
                self.assertTrue(project, 'Failed opening project: ' + entryId)

                if useNrgArchive: # default is False
    #                inputArchiveDir = os.path.join('/Library/WebServer/Documents/NRG-CING/recoordSync', entryId)
                    # Mounted from nmr.cmbi.ru.nl
    #                inputArchiveDir = os.path.join('/Volumes/tria1/Library/WebServer/Documents/NRG-CING/recoordSync', entryId)
                    inputArchiveDir = os.path.join('/Users/jd/ccpn_tmp/data/recoord', entryId)
                else:
                    inputArchiveDir = os.path.join(cingDirTestsData, "ccpn")

                ccpnFile = os.path.join(inputArchiveDir, entryId + ".tgz")
                if not os.path.exists(ccpnFile):
                    ccpnFile = os.path.join(inputArchiveDir, entryId + ".tar.gz")
                    if not os.path.exists(ccpnFile):
                        self.fail("Neither %s or the .tgz exist" % ccpnFile)

                if doSwapCheck: # Need to start with ccpn without loading into CING api yet.
                    if os.path.exists(entryId):
                        nTmessage("Removing previous directory: %s" % entryId)
                        rmtree(entryId)
                    do_cmd("tar -xzf " + ccpnFile) # will extract to local dir.
                    if os.path.exists('linkNmrStarData'):
                        nTmessage("Renaming standard directory linkNmrStarData to entry: %s" % entryId)
                        os.rename('linkNmrStarData', entryId)

                    ccpnProject = loadProject(entryId)
                    if not ccpnProject:
                        self.fail("Failed to read project: %s" % entryId)
            #        constraintsHandler = ConstraintsHandler()
                    nmrConstraintStore = ccpnProject.findFirstNmrConstraintStore()
                    structureEnsemble = ccpnProject.findFirstStructureEnsemble()
                    numSwapCheckRuns = 2
                    if nmrConstraintStore:
                        if structureEnsemble:
                            swapCheck(nmrConstraintStore, structureEnsemble, numSwapCheckRuns)
                        else:
                            nTmessage("Failed to find structureEnsemble; skipping swapCheck")
                    else:
                        nTmessage("Failed to find nmrConstraintStore; skipping swapCheck")
            #        constraintsHandler.swapCheck(nmrConstraintStore, structureEnsemble, numSwapCheckRuns)
                    nTmessage('Saving to new path')
            #        checkValid=True,
                    saveProject(ccpnProject, newPath=entryId, removeExisting=True)
                    ccpnFile = entryId # set to local dir now.
                # end if doSwapCheck
                self.assertTrue(project.initCcpn(ccpnFolder = ccpnFile, modelCount=modelCount))
#                if doSave:
#                    self.assertTrue(project.save())

            if False:
                ranges = "173-183"
#                residueOfInterest = range(171,174)
#                for residue in project.molecule.A.allResidues():
#                    if residue.resNum not in residueOfInterest:
#    #                    nTmessage("Removing residue of no interest")
#                        project.molecule.A.removeResidue(residue)
            if False:
                ccpnProject = project.ccpn
                printSequenceFromCcpnProject(ccpnProject)

            if True:
                self.assertFalse(project.molecule.setRanges(ranges))
                nTdebug('In test_ccpn.py: ranges: %s' % str(project.molecule.ranges))
                project.molecule.rangesToMmCifRanges(ranges)

            if True:
                self.assertFalse(project.validate(htmlOnly = htmlOnly,
                                              ranges=ranges,
#                                              fastestTest=fastestTest, # disabled
                                              doProcheck = doProcheck,
                                              doWhatif = doWhatif,
                                              doWattos=doWattos,
                                              doQueeny = doQueeny,
                                              doTalos=doTalos,
                                              filterVasco=filterVasco,
                                              filterTopViolations = filterTopViolations
                                               ))
                if doWattos and False:
                    mol = project.molecule
                    completenessMol = mol.getDeepByKeys( WATTOS_STR, COMPLCHK_STR, VALUE_LIST_STR)
                    nTdebug("completenessMol: %s" % completenessMol)
                    for res in mol.allResidues():
                        completenessRes = res.getDeepByKeys( WATTOS_STR, COMPLCHK_STR, VALUE_LIST_STR)
                        nTdebug("%s: %s" % (res, completenessRes))
                    # end for
                # end if
                color = project.molecule.getRogColor()
                nTdebug("The color of this molecule is: %s" % color)
                self.assertFalse( color == COLOR_RED ) # ;-)
            # end if
#            self.assertTrue(project.exportValidation2ccpn())
#            self.assertFalse(project.removeCcpnReferences())
            # Do not leave the old CCPN directory laying around since it might get added to by another test.
#            if os.path.exists(entryId):
#                self.assertFalse(shutil.rmtree(entryId))

            if False:
                self.assertTrue(project.save())
                self.assertTrue(project.saveCcpn(entryId))

            if doRestoreCheck:
                del project
                project = Project.open(entryId, status = 'old')
                self.assertTrue(project, 'Failed reopening project: ' + entryId)
            if doStoreCheck:
#                # Does require below import which is used here to trigger import warning in case it's not installed.
                # pylint: disable=W0612
                from cing.PluginCode.sqlAlchemy import CsqlAlchemy #@UnusedImport # pylint: disable=W0404
                if doStoreCING2db( entryId, ARCHIVE_NRG_ID, project=project):
                    nTerror("Failed to store CING project's data to DB but continuing.")
            if doSave:
                self.assertTrue(project.save())
Example #30
0
def replaceCoordinates():

    cityList = [ 'Cheshire', 'Frankfurt', 'Lyon', 'Paris', 'Piscataway', 'Seattle', 'Utrecht' ]
    maxCities = 1
    maxEntries = 1
    # Adjust the parameters below!
    removeOriginalStructureEnsemble = True
    addStructureEnsemble = True # From all *.pdb files in inputDir.

    dataOrgDir = os.path.join(baseDir,DATA_STR)
    dataDividedDir = os.path.join(baseDir,DATA_STR)
    #        _scriptName = sys.argv[0]
    # parameters for doScriptOnEntryList
    startDir = '/Library/WebServer/Documents/' + CASD_NMR_BASE_NAME
    entryListFileName = os.path.join(startDir, 'list', 'entry_list_todo.csv')
    entryList = readLinesFromFile(entryListFileName) #@UnusedVariable
    entryList = ['ET109Aox']

    for entryCode in entryList[0:maxEntries]:
        ch23 = entryCode[1:3]
        dataOrgEntryDir = os.path.join( dataOrgDir, entryCode )
        ccpnFile = os.path.join(dataOrgEntryDir, entryCode+".tgz")
        for city in cityList[0:maxCities]:
            entryCodeNew = entryCode + city
            dataDividedXDir = os.path.join(dataDividedDir, ch23)
            inputAuthorDir = os.path.join(dataDividedXDir, entryCodeNew, 'Author')
            outputNijmegenDir = os.path.join(dataDividedXDir, entryCodeNew, 'Nijmegen')

            globPattern = inputAuthorDir + '/*.pdb'
            pdbFileList = glob(globPattern)
            if not pdbFileList:
                nTmessage("Skipping because there is no PDB file in: " + os.getcwd())
                continue

            if not os.path.exists(inputAuthorDir):
                mkdirs(inputAuthorDir)
            if not os.path.exists(outputNijmegenDir):
                mkdirs(outputNijmegenDir)

            os.chdir(outputNijmegenDir)
            if False:
                # By reading the ccpn tgz into cing it is also untarred/tested.
                project = Project.open(entryCode, status = 'new')
                project.initCcpn(ccpnFolder = ccpnFile, modelCount=1)
                project.removeFromDisk()
                project.close(save=False)

            if True:
                ccpnProject = loadProject(entryCode)
                nmrProject = ccpnProject.currentNmrProject
                ccpnMolSystem = ccpnProject.findFirstMolSystem()
                nTmessage( 'found ccpnMolSystem: %s' % ccpnMolSystem )
            #    print 'status: %s' % ccpnMolSystem.setCode(projectName) # impossible; reported to ccpn team.

                if removeOriginalStructureEnsemble:
                    structureEnsemble = ccpnProject.findFirstStructureEnsemble()
                    if structureEnsemble:
                        nTmessage("Removing first found structureEnsemble")
                        structureEnsemble.delete()
                    else:
                        nTwarning("No structureEnsemble found; can't remove it.")

                if addStructureEnsemble:
                    structureGeneration = nmrProject.newStructureGeneration()
                    fileList = None
                    nTdebug("From %s will read files: %s" % (globPattern,fileList))
                    guiRoot = Tkinter.Tk()
                    format = PseudoPdbFormat(ccpnProject, guiRoot, verbose = 1)
                    format.readCoordinates(fileList, strucGen = structureGeneration, minimalPrompts = 1, linkAtoms = 0)

                nTmessage(  'saving to new path if all checks are valid' )
                # the newPath basename will be taken according to ccpn code doc.
                saveProject(ccpnProject, checkValid=True, newPath=entryCodeNew, removeExisting=True)
Example #31
0
def annotateEntry(entry_code, bmrb_id, *extraArgList):
    'Return True on error'
    nTmessage(header)
    nTmessage(getStartMessage())

    expectedArgumentList = []
    expectedNumberOfArguments = len(expectedArgumentList)
    if len(extraArgList) != expectedNumberOfArguments:
        nTerror("Got arguments: " + repr(extraArgList))
        nTerror("Failed to get expected number of arguments: %d got %d" % (
            expectedNumberOfArguments, len(extraArgList)))
        nTerror("Expected arguments: %s" % expectedArgumentList)
        return True
#    entry_code, city = entryCodePlusCity.split('_')

    # Adjust the parameters below
    isInteractive = False
    checkOrgProject = False
    doSwapCheck = False
    doSaveProject = True
    doExport = True

    minimalPrompts = True
    verbose = True
    allowPopups = False

    if isInteractive:
        allowPopups = True
        minimalPrompts = False
#        verbose = True
    else:
        pass
#        minimalPrompts = True
#        verbose = False

    print 'entry_code                                                                                    ', entry_code
    print 'bmrb_id                                                                                       ', bmrb_id
    print 'allowPopups                                                                                   ', allowPopups
    print 'isInteractive                                                                                 ', isInteractive
    print 'minimalPrompts                                                                                ', minimalPrompts
    print 'verbose                                                                                       ', verbose
    print 'checkOrgProject                                                                               ', checkOrgProject
    print 'doSwapCheck                                                                                   ', doSwapCheck
    print 'doSaveProject                                                                                 ', doSaveProject
    print 'doExport                                                                                      ', doExport

    guiRoot = None
    if allowPopups:
        guiRoot = Tkinter.Tk()

    ch23 = entry_code[1:3]
    dataOrgEntryDir = os.path.join(results_dir, 'recoordSync', entry_code)
    ccpnFile = os.path.join(dataOrgEntryDir, entry_code + ".tgz")
    if not os.path.exists(ccpnFile):
        nTerror("Input file not found: %s" % ccpnFile)
        return True
    nTdebug("Looking at %s" % entry_code)
#                continue # TODO disable premature stop.

    bmrb_code = 'bmr'+bmrb_id

    digits12 ="%02d" % ( bmrb_id % 100 )
    inputStarDir = os.path.join(bmrbDir, digits12)
    if not os.path.exists(inputStarDir):
        nTerror("Input star dir not found: %s" % inputStarDir)
        return True
    inputStarFile = os.path.join(inputStarDir, '%s.str'%bmrb_code)
    if not os.path.exists(inputStarFile):
        nTerror("inputStarFile not found: %s" % inputStarFile)
        return True

    dataDividedXDir = os.path.join(nrgPlusDir, ch23)
    entryDir = os.path.join(dataDividedXDir, entry_code)
    outputNijmegenDir = os.path.join(entryDir, 'Nijmegen')
    if not os.path.exists(outputNijmegenDir):
        mkdirs(outputNijmegenDir)
    os.chdir(outputNijmegenDir)

    presets = getDeepByKeysOrDefault(presetDict, {}, bmrb_code)
    if presets:
        nTmessage("In annotateLoop using preset values...")
        nTdebug(str(presets))

    if os.path.exists(entry_code):
        nTmessage("Removing previous directory: %s" % entry_code)
        rmtree(entry_code)
    do_cmd("tar -xzf " + ccpnFile)
    if os.path.exists('linkNmrStarData'):
        nTmessage("Renaming standard directory linkNmrStarData to entry: %s" % entry_code)
        os.rename('linkNmrStarData', entry_code)

    if checkOrgProject:
        # By reading the ccpn tgz into cing it is also untarred/tested.
        project = Project.open(entry_code, status='new')
        if not project.initCcpn(ccpnFolder=ccpnFile, modelCount=1):
            nTerror("Failed check of original project")
            return True
        project.removeFromDisk()
        project.close(save=False)

    ccpnProject = loadProject(entry_code)
    if not ccpnProject:
        nTerror("Failed to read project: %s" % entry_code)
        return True

#            nmrProject = ccpnProject.currentNmrProject
#            ccpnMolSystem = ccpnProject.findFirstMolSystem()
#            nTmessage('found ccpnMolSystem: %s' % ccpnMolSystem)
#    print 'status: %s' % ccpnMolSystem.setCode(projectName) # impossible; reported to ccpn team.

    importStarChemicalShifts(ccpnProject, inputStarDir, guiRoot, allowPopups=allowPopups, minimalPrompts=minimalPrompts, 
                             verbose=verbose, **presets)

    if doSwapCheck:
#        constraintsHandler = ConstraintsHandler()
        nmrConstraintStore = ccpnProject.findFirstNmrConstraintStore()
        structureEnsemble = ccpnProject.findFirstStructureEnsemble()
        numSwapCheckRuns = 3
        if nmrConstraintStore:
            if structureEnsemble:
                swapCheck(nmrConstraintStore, structureEnsemble, numSwapCheckRuns)
            else:
                nTmessage("Failed to find structureEnsemble; skipping swapCheck")
        else:
            nTmessage("Failed to find nmrConstraintStore; skipping swapCheck")
#        constraintsHandler.swapCheck(nmrConstraintStore, structureEnsemble, numSwapCheckRuns)

    if doSaveProject:
#        nTmessage('Checking validity and saving to new path')
        nTmessage('Saving to new path')
#        checkValid=True,
        saveProject(ccpnProject, newPath=entry_code, removeExisting=True)
    if doExport:
        tarPath = os.path.join(entryDir, entry_code + ".tgz")
        if os.path.exists(tarPath):
            nTmessage("Overwriting: " + tarPath)
        myTar = tarfile.open(tarPath, mode='w:gz') # overwrites
        myTar.add(entry_code)
        myTar.close()
    if guiRoot:
        guiRoot.destroy()
Example #32
0
def annotateEntry(entryCodeNew, *extraArgList):
    nTmessage(header)
    nTmessage(getStartMessage())

    expectedArgumentList = []
    expectedNumberOfArguments = len(expectedArgumentList)
    if len(extraArgList) != expectedNumberOfArguments:
        nTerror("Got arguments: " + repr(extraArgList))
        nTerror("Failed to get expected number of arguments: %d got %d" % (
            expectedNumberOfArguments, len(extraArgList)))
        nTerror("Expected arguments: %s" % expectedArgumentList)
        return True
#    entryCode, city = entryCodePlusCity.split('_')

    # Adjust the parameters below
    isInteractive = False
    sourceIsOrgProject = True
    checkOrgProject = False
    replaceCoordinates = True # From all *.pdb files in inputDir.
    replaceRestraints = True
    doSwapCheck = True
    doSaveProject = True
    doExport = True

    minimalPrompts = True
    verbose = True

    if isInteractive:
        allowPopups = True
        minimalPrompts = False
#        verbose = True
    else:
        allowPopups = False
#        minimalPrompts = True
#        verbose = False

    print 'allowPopups                                                                                   ', allowPopups
    print 'isInteractive                                                                                 ', isInteractive
    print 'minimalPrompts                                                                                ', minimalPrompts
    print 'verbose                                                                                       ', verbose
    print 'sourceIsOrgProject                      (or new CCPN file)                                    ', sourceIsOrgProject
    print 'checkOrgProject                                                                               ', checkOrgProject
    print 'replaceCoordinates                                                                            ', replaceCoordinates
    print 'replaceRestraints                                                                             ', replaceRestraints
    print 'doSwapCheck                                                                                   ', doSwapCheck
    print 'doSaveProject                                                                                 ', doSaveProject
    print 'doExport                                                                                      ', doExport

    guiRoot = None
    if allowPopups:
        guiRoot = Tkinter.Tk()

    entryCode,city = mapEntrycodeNew2EntrycodeAndCity[entryCodeNew]
    ch23 = entryCode[1:3]
    entryCodeOrg = entryCode + 'Org'
    dataOrgEntryDir = os.path.join(dataDir, ch23, entryCodeOrg)
    ccpnFile = os.path.join(dataOrgEntryDir, entryCodeOrg + ".tgz")
#    entryCodeNew = entryCode + city
    programId = getDeepByKeys(programHoH, entryCode, city)
    if not (city == 'Test' or programId):
#                nTdebug("Skipping %s" % entryCodeNew)
        nTerror("Neither City is 'Test' or programId given")
        return
    else:
        nTdebug("Looking at %s" % entryCodeNew)
#                continue # TODO disable premature stop.


    dataDividedXDir = os.path.join(dataDir, ch23)
    entryDir = os.path.join(dataDividedXDir, entryCodeNew)
    inputAuthorDir = os.path.join(entryDir, 'Author')
    outputNijmegenDir = os.path.join(entryDir, 'Nijmegen')

    if not os.path.exists(inputAuthorDir):
        mkdirs(inputAuthorDir)
    if not os.path.exists(outputNijmegenDir):
        mkdirs(outputNijmegenDir)

    os.chdir(outputNijmegenDir)

    presets = getDeepByKeysOrDefault(presetDict, {}, entryCodeNew)
    if presets:
        nTmessage("In annotateLoop using preset values...")
    # end if

    if sourceIsOrgProject:
        if os.path.exists(entryCodeOrg):
            nTmessage("Removing previous Org directory: %s" % entryCodeOrg)
            rmtree(entryCodeOrg)
        do_cmd("tar -xzf " + ccpnFile)
        if os.path.exists(entryCodeNew):
            nTmessage("Removing previous directory: %s" % entryCodeNew)
            rmtree(entryCodeNew)
        copytree(entryCodeOrg, entryCodeNew)

    if checkOrgProject:
        # By reading the ccpn tgz into cing it is also untarred/tested.
        project = Project.open(entryCodeOrg, status='new')
        if not project.initCcpn(ccpnFolder=ccpnFile, modelCount=1):
            nTerror("Failed check of original project")
            return
        project.removeFromDisk()
        project.close(save=False)

    ccpnProject = loadProject(entryCodeNew)
    if not ccpnProject:
        nTerror("Failed to read project: %s" % entryCodeNew)
        return

#            nmrProject = ccpnProject.currentNmrProject
#            ccpnMolSystem = ccpnProject.findFirstMolSystem()
#            nTmessage('found ccpnMolSystem: %s' % ccpnMolSystem)
#    print 'status: %s' % ccpnMolSystem.setCode(projectName) # impossible; reported to ccpn team.

    if replaceCoordinates or replaceRestraints:
        if programId == CYANA:
            importCyanaCoorAndRes(ccpnProject, inputAuthorDir, guiRoot,
                replaceCoordinates=replaceCoordinates, replaceRestraints=replaceRestraints, 
                allowPopups=allowPopups, minimalPrompts=minimalPrompts, verbose=verbose, **presets)
        elif programId == XPLOR:
            importXplorCoorAndRes(ccpnProject, inputAuthorDir, guiRoot,
                replaceCoordinates=replaceCoordinates, replaceRestraints=replaceRestraints, 
                allowPopups=allowPopups, minimalPrompts=minimalPrompts, verbose=verbose, **presets)
        elif programId == PDB:
            importPseudoPdb(ccpnProject, inputAuthorDir, guiRoot,
                allowPopups=allowPopups, minimalPrompts=minimalPrompts, verbose=verbose, **presets)
        else:
            nTerror("Failed to doImportCoordinatesAndRestraints because action for program Id not coded for: %s" % programId)
            nTerror("Skipping entry")
            return

    if doSwapCheck:
#        constraintsHandler = ConstraintsHandler()
        nmrConstraintStore = ccpnProject.findFirstNmrConstraintStore()
        structureEnsemble = ccpnProject.findFirstStructureEnsemble()
        numSwapCheckRuns = 3
        if nmrConstraintStore:
            if structureEnsemble:
                swapCheck(nmrConstraintStore, structureEnsemble, numSwapCheckRuns)
            else:
                nTmessage("Failed to find structureEnsemble; skipping swapCheck")
        else:
            nTmessage("Failed to find nmrConstraintStore; skipping swapCheck")
#        constraintsHandler.swapCheck(nmrConstraintStore, structureEnsemble, numSwapCheckRuns)

    if doSaveProject:
#        nTmessage('Checking validity and saving to new path')
        nTmessage('Saving to new path: %s' % entryCodeNew)
#        checkValid=True,
        saveProject(ccpnProject, newPath=entryCodeNew, removeExisting=True)
    if doExport:
        tarPath = os.path.join(entryDir, entryCodeNew + ".tgz")
        if os.path.exists(tarPath):
            nTmessage("Overwriting: " + tarPath)
        myTar = tarfile.open(tarPath, mode='w:gz') # overwrites
        myTar.add(entryCodeNew)
        myTar.close()
    if guiRoot:
        guiRoot.destroy()
Example #33
0
def convert(projectName,
            inputDir,
            outputFile,
            excludeSaveFrames=('general_distance_constraints', )):

    print "projectName: %s" % projectName
    print "inputDir: %s" % inputDir
    print "outputFile: %s" % outputFile
    print "excludeSaveFrames: %s" % excludeSaveFrames
    ccpnPath = os.path.join(inputDir, projectName)
    ccpnProject = loadProject(ccpnPath)

    nmrEntryStore = ccpnProject.newNmrEntryStore(name="newNmrEntryStoreName")
    molSystem = ccpnProject.findFirstMolSystem()
    nmrEntry = nmrEntryStore.newEntry(molSystem=molSystem,
                                      name='newNmrEntryName')

    nmrProject = ccpnProject.currentNmrProject

    nmrEntry.structureGenerations = nmrProject.sortedStructureGenerations()
    if nmrEntry.structureGenerations:
        print "Using structureGenerations from nmrProject"
    else:
        ncs = ccpnProject.findFirstNmrConstraintStore()
        sG = None
        if not ncs:
            print "Failed to find any NmrConstraintStore from project"
        else:
            sG = ncs.findFirstStructureGeneration()
        if sG:
            nmrEntry.addStructureGeneration(sG)
            print "Using structureGenerations from nmrProject"
        else:
            print "Failed to find nmrEntry.structureGenerations from nmrProject or nmrConstraintStore; creating a new one."
            strucGen = nmrProject.newStructureGeneration()
            nmrEntry.addStructureGeneration(strucGen)
        # end if
        # end if
    # end if

    try:  # ccpn stable as 08 Jul 2009
        nmrEntry.structureAnalyses = nmrProject.sortedStructureAnalysiss(
        )  # watch out for misspelling.
    except AttributeError:  # ccpn trunk fixed misspelled function
        nmrEntry.structureAnalyses = nmrProject.sortedStructureAnalyses()
    if not nmrEntry.structureAnalyses:
        print "Failed to find nmrEntry.structureAnalyses"
    nmrEntry.measurementLists = nmrProject.sortedMeasurementLists()
    if not nmrEntry.measurementLists:
        print "Failed to find nmrEntry.measurementLists"

    # Hack to hook up coordinates, hopefully correctly (Wim 30/04/2009)
    if nmrEntry.structureGenerations:
        hasStructureEnsemble = False
        for strucGen in nmrEntry.structureGenerations:
            if strucGen.structureEnsemble:
                hasStructureEnsemble = True
                break
            # end if
        # end for
        print "hasStructureEnsemble: %s" % hasStructureEnsemble
        # This will only work dependably if there is one structureGeneration, one structureEnsemble...
        # Take the one that was created last in any case, fingers crossed that they match up!
        if not hasStructureEnsemble and ccpnProject.structureEnsembles:
            nmrEntry.sortedStructureGenerations(
            )[-1].structureEnsemble = ccpnProject.sortedStructureEnsembles(
            )[-1]
        # end if
    # end if

    for ne in nmrProject.sortedExperiments():  # will be sortedNmrExperiments
        for ds in ne.sortedDataSources():
            for pl in ds.sortedPeakLists():
                nmrEntry.addPeakList(pl)

    nmrStarExport = NmrStarExport(nmrEntry,
                                  nmrStarVersion='3.1',
                                  forceEntryId='1')
    nmrStarExport.createFile(outputFile,
                             excludeSaveFrames=excludeSaveFrames,
                             verbose=True)

    # Set the header comment - only set this if you need a standard header!
    topComment = "# File written for CING by NmrStarExport.py code"
    nmrStarExport.writeFile(title="CING", topComment=topComment, verbose=True)
Example #34
0
def annotateEntry(entry_code, bmrb_id, *extraArgList):
    'Return True on error'
    nTmessage(header)
    nTmessage(getStartMessage())

    expectedArgumentList = []
    expectedNumberOfArguments = len(expectedArgumentList)
    if len(extraArgList) != expectedNumberOfArguments:
        nTerror("Got arguments: " + repr(extraArgList))
        nTerror("Failed to get expected number of arguments: %d got %d" %
                (expectedNumberOfArguments, len(extraArgList)))
        nTerror("Expected arguments: %s" % expectedArgumentList)
        return True
#    entry_code, city = entryCodePlusCity.split('_')

# Adjust the parameters below
    isInteractive = False
    checkOrgProject = False
    doSwapCheck = False
    doSaveProject = True
    doExport = True

    minimalPrompts = True
    verbose = True
    allowPopups = False

    if isInteractive:
        allowPopups = True
        minimalPrompts = False
#        verbose = True
    else:
        pass
#        minimalPrompts = True
#        verbose = False

    print 'entry_code                                                                                    ', entry_code
    print 'bmrb_id                                                                                       ', bmrb_id
    print 'allowPopups                                                                                   ', allowPopups
    print 'isInteractive                                                                                 ', isInteractive
    print 'minimalPrompts                                                                                ', minimalPrompts
    print 'verbose                                                                                       ', verbose
    print 'checkOrgProject                                                                               ', checkOrgProject
    print 'doSwapCheck                                                                                   ', doSwapCheck
    print 'doSaveProject                                                                                 ', doSaveProject
    print 'doExport                                                                                      ', doExport

    guiRoot = None
    if allowPopups:
        guiRoot = Tkinter.Tk()

    ch23 = entry_code[1:3]
    dataOrgEntryDir = os.path.join(results_dir, 'recoordSync', entry_code)
    ccpnFile = os.path.join(dataOrgEntryDir, entry_code + ".tgz")
    if not os.path.exists(ccpnFile):
        nTerror("Input file not found: %s" % ccpnFile)
        return True
    nTdebug("Looking at %s" % entry_code)
    #                continue # TODO disable premature stop.

    bmrb_code = 'bmr' + bmrb_id

    digits12 = "%02d" % (bmrb_id % 100)
    inputStarDir = os.path.join(bmrbDir, digits12)
    if not os.path.exists(inputStarDir):
        nTerror("Input star dir not found: %s" % inputStarDir)
        return True
    inputStarFile = os.path.join(inputStarDir, '%s.str' % bmrb_code)
    if not os.path.exists(inputStarFile):
        nTerror("inputStarFile not found: %s" % inputStarFile)
        return True

    dataDividedXDir = os.path.join(nrgPlusDir, ch23)
    entryDir = os.path.join(dataDividedXDir, entry_code)
    outputNijmegenDir = os.path.join(entryDir, 'Nijmegen')
    if not os.path.exists(outputNijmegenDir):
        mkdirs(outputNijmegenDir)
    os.chdir(outputNijmegenDir)

    presets = getDeepByKeysOrDefault(presetDict, {}, bmrb_code)
    if presets:
        nTmessage("In annotateLoop using preset values...")
        nTdebug(str(presets))

    if os.path.exists(entry_code):
        nTmessage("Removing previous directory: %s" % entry_code)
        rmtree(entry_code)
    do_cmd("tar -xzf " + ccpnFile)
    if os.path.exists('linkNmrStarData'):
        nTmessage("Renaming standard directory linkNmrStarData to entry: %s" %
                  entry_code)
        os.rename('linkNmrStarData', entry_code)

    if checkOrgProject:
        # By reading the ccpn tgz into cing it is also untarred/tested.
        project = Project.open(entry_code, status='new')
        if not project.initCcpn(ccpnFolder=ccpnFile, modelCount=1):
            nTerror("Failed check of original project")
            return True
        project.removeFromDisk()
        project.close(save=False)

    ccpnProject = loadProject(entry_code)
    if not ccpnProject:
        nTerror("Failed to read project: %s" % entry_code)
        return True

#            nmrProject = ccpnProject.currentNmrProject
#            ccpnMolSystem = ccpnProject.findFirstMolSystem()
#            nTmessage('found ccpnMolSystem: %s' % ccpnMolSystem)
#    print 'status: %s' % ccpnMolSystem.setCode(projectName) # impossible; reported to ccpn team.

    importStarChemicalShifts(ccpnProject,
                             inputStarDir,
                             guiRoot,
                             allowPopups=allowPopups,
                             minimalPrompts=minimalPrompts,
                             verbose=verbose,
                             **presets)

    if doSwapCheck:
        #        constraintsHandler = ConstraintsHandler()
        nmrConstraintStore = ccpnProject.findFirstNmrConstraintStore()
        structureEnsemble = ccpnProject.findFirstStructureEnsemble()
        numSwapCheckRuns = 3
        if nmrConstraintStore:
            if structureEnsemble:
                swapCheck(nmrConstraintStore, structureEnsemble,
                          numSwapCheckRuns)
            else:
                nTmessage(
                    "Failed to find structureEnsemble; skipping swapCheck")
        else:
            nTmessage("Failed to find nmrConstraintStore; skipping swapCheck")
#        constraintsHandler.swapCheck(nmrConstraintStore, structureEnsemble, numSwapCheckRuns)

    if doSaveProject:
        #        nTmessage('Checking validity and saving to new path')
        nTmessage('Saving to new path')
        #        checkValid=True,
        saveProject(ccpnProject, newPath=entry_code, removeExisting=True)
    if doExport:
        tarPath = os.path.join(entryDir, entry_code + ".tgz")
        if os.path.exists(tarPath):
            nTmessage("Overwriting: " + tarPath)
        myTar = tarfile.open(tarPath, mode='w:gz')  # overwrites
        myTar.add(entry_code)
        myTar.close()
    if guiRoot:
        guiRoot.destroy()
Example #35
0
def convert(projectName, inputDir, outputFile, excludeSaveFrames=("general_distance_constraints",)):

    print "projectName: %s" % projectName
    print "inputDir: %s" % inputDir
    print "outputFile: %s" % outputFile
    print "excludeSaveFrames: %s" % excludeSaveFrames
    ccpnPath = os.path.join(inputDir, projectName)
    ccpnProject = loadProject(ccpnPath)

    nmrEntryStore = ccpnProject.newNmrEntryStore(name="newNmrEntryStoreName")
    molSystem = ccpnProject.findFirstMolSystem()
    nmrEntry = nmrEntryStore.newEntry(molSystem=molSystem, name="newNmrEntryName")

    nmrProject = ccpnProject.currentNmrProject

    nmrEntry.structureGenerations = nmrProject.sortedStructureGenerations()
    if nmrEntry.structureGenerations:
        print "Using structureGenerations from nmrProject"
    else:
        ncs = ccpnProject.findFirstNmrConstraintStore()
        sG = None
        if not ncs:
            print "Failed to find any NmrConstraintStore from project"
        else:
            sG = ncs.findFirstStructureGeneration()
        if sG:
            nmrEntry.addStructureGeneration(sG)
            print "Using structureGenerations from nmrProject"
        else:
            print "Failed to find nmrEntry.structureGenerations from nmrProject or nmrConstraintStore; creating a new one."
            strucGen = nmrProject.newStructureGeneration()
            nmrEntry.addStructureGeneration(strucGen)
        # end if
        # end if
    # end if

    try:  # ccpn stable as 08 Jul 2009
        nmrEntry.structureAnalyses = nmrProject.sortedStructureAnalysiss()  # watch out for misspelling.
    except AttributeError:  # ccpn trunk fixed misspelled function
        nmrEntry.structureAnalyses = nmrProject.sortedStructureAnalyses()
    if not nmrEntry.structureAnalyses:
        print "Failed to find nmrEntry.structureAnalyses"
    nmrEntry.measurementLists = nmrProject.sortedMeasurementLists()
    if not nmrEntry.measurementLists:
        print "Failed to find nmrEntry.measurementLists"

    # Hack to hook up coordinates, hopefully correctly (Wim 30/04/2009)
    if nmrEntry.structureGenerations:
        hasStructureEnsemble = False
        for strucGen in nmrEntry.structureGenerations:
            if strucGen.structureEnsemble:
                hasStructureEnsemble = True
                break
            # end if
        # end for
        print "hasStructureEnsemble: %s" % hasStructureEnsemble
        # This will only work dependably if there is one structureGeneration, one structureEnsemble...
        # Take the one that was created last in any case, fingers crossed that they match up!
        if not hasStructureEnsemble and ccpnProject.structureEnsembles:
            nmrEntry.sortedStructureGenerations()[-1].structureEnsemble = ccpnProject.sortedStructureEnsembles()[-1]
        # end if
    # end if

    for ne in nmrProject.sortedExperiments():  # will be sortedNmrExperiments
        for ds in ne.sortedDataSources():
            for pl in ds.sortedPeakLists():
                nmrEntry.addPeakList(pl)

    nmrStarExport = NmrStarExport(nmrEntry, nmrStarVersion="3.1", forceEntryId="1")
    nmrStarExport.createFile(outputFile, excludeSaveFrames=excludeSaveFrames, verbose=True)

    # Set the header comment - only set this if you need a standard header!
    topComment = "# File written for CING by NmrStarExport.py code"
    nmrStarExport.writeFile(title="CING", topComment=topComment, verbose=True)