def convert(projectName, rootDir): datasetDir = os.path.join(rootDir, projectName) nijmegenDir = os.path.join(datasetDir, "Nijmegen") authorDir = os.path.join(datasetDir, "Authors") os.chdir(nijmegenDir) projectPath = os.path.join(nijmegenDir, projectName) if os.path.exists(projectPath): shutil.rmtree(projectPath) project = Implementation.MemopsRoot(name = projectName) nmrProject = project.newNmrProject(name = project.name) structureGeneration = nmrProject.newStructureGeneration() guiRoot = Tkinter.Tk() format = PseudoPdbFormat(project, guiRoot, verbose = 1) globPattern = authorDir + '/*.pdb' fileList = glob(globPattern) nTdebug("From %s will read files: %s" % (globPattern,fileList)) format.readCoordinates(fileList, strucGen = structureGeneration, minimalPrompts = 1, linkAtoms = 0) project.saveModified() tgzFileName = "../"+projectName + ".tgz" cmd = "tar -czf %s %s" % (tgzFileName, projectName) do_cmd(cmd)
def importPdbCoords(self): if not self.project: showWarning('Failure','Please create a new CCPN project.', parent=self) return fileTypes = [ FileType('PDB', ['*.pdb']), FileType('PDB Entry', ['*.ent']), FileType('All', ['*']) ] fileSelectPopup = FileSelectPopup(self, file_types=fileTypes, title='Import PDB coordinates file', dismiss_text='Cancel', selected_file_must_exist=True, multiSelect=False,) fileName = fileSelectPopup.getFile() if not os.path.exists(fileName): showWarning('Failure','No such file.', parent=self) return if fileName: name = os.path.split(fileName)[1] if '.' in name: name = name.split('.')[0] pdbObj = PseudoPdbFormat(self.project, self, verbose=True) pdbObj.readCoordinates(fileName, minimalPrompts=True) self.eciFrame.updateAll() return pdbObj
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)
def convert(projectName, rootDir): datasetDir = os.path.join(rootDir, projectName) nijmegenDir = os.path.join(datasetDir, "Nijmegen") authorDir = os.path.join(datasetDir, "Authors") os.chdir(nijmegenDir) projectPath = os.path.join(nijmegenDir, projectName) if os.path.exists(projectPath): shutil.rmtree(projectPath) project = Implementation.MemopsRoot(name=projectName) nmrProject = project.newNmrProject(name=project.name) structureGeneration = nmrProject.newStructureGeneration() guiRoot = Tkinter.Tk() format = PseudoPdbFormat(project, guiRoot, verbose=1) globPattern = authorDir + '/*.pdb' fileList = glob(globPattern) nTdebug("From %s will read files: %s" % (globPattern, fileList)) format.readCoordinates(fileList, strucGen=structureGeneration, minimalPrompts=1, linkAtoms=0) project.saveModified() tgzFileName = "../" + projectName + ".tgz" cmd = "tar -czf %s %s" % (tgzFileName, projectName) do_cmd(cmd)
def importPseudoPdb(ccpnProject, inputDir, guiRoot, allowPopups=1, minimalPrompts=0, verbose=1, **presets): nTdebug("Using presets %s" % repr(presets)) formatPseudoPdb = PseudoPdbFormat(ccpnProject, guiRoot, verbose=verbose, minimalPrompts=minimalPrompts, allowPopups=allowPopups) nmrProject = ccpnProject.currentNmrProject # nmrProject = project.newNmrProject(name=project.name) structureEnsembleList = ccpnProject.sortedStructureEnsembles() if len(structureEnsembleList) != 1: nTerror("Failed to find single structureEnsemble; instead found: %d" % len(structureEnsembleList) ) structureEnsemble = ccpnProject.findFirstStructureEnsemble() if structureEnsemble: nTmessage("In importPseudoPdb, removing first found structureEnsemble") structureEnsemble.delete() else: nTwarning("No structureEnsemble found; can't remove it.") structureGenerationList = nmrProject.sortedStructureGenerations() if not structureGenerationList: nTdebug("No or empty structureGenerationList; creating a new one.") nmrProject.newStructureGeneration() structureGenerationList = nmrProject.sortedStructureGenerations() if len(structureGenerationList) != 1: nTerror("Failed to find single structureGeneration; instead found: %d" % len(structureGenerationList) ) structureGeneration = structureGenerationList[0] # structureGeneration = nmrProject.findFirstStructureGeneration() # structureGeneration = nmrProject.newStructureGeneration() if not structureGeneration: nTerror("Failed to find or create structureGeneration") return True globPattern = inputDir + '/*.pdb' fileList = glob(globPattern) nTdebug("From %s will read files: %s" % (globPattern, fileList)) if len(fileList) != 1: nTerror("Failed to find single PDB file; instead found list: %s" % repr(fileList)) return True keywds = getDeepByKeysOrDefault(presets, {}, READ_COORDINATES, KEYWORDS) nTdebug("In importPseudoPdb: from getDeepByKeysOrDefault keywds: %s" % repr(keywds)) reportDifference(ccpnProject, fileList[0]) status = formatPseudoPdb.readCoordinates(fileList, strucGen=structureGeneration, linkAtoms=0, swapFirstNumberAtom=1, minimalPrompts=minimalPrompts, verbose=verbose, **keywds) if not status: # can return None or False on error nTerror("Failed to formatPseudoPdb.readCoordinates") return True # returns True on error
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)
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)
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)