Beispiel #1
0
def setDataSourceDataStore(dataSource,
                           dataUrlPath,
                           localPath,
                           dataLocationStore=None,
                           dataUrl=None):

    #
    # Get DataLocationStore
    #

    if not dataLocationStore:

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

    #
    # Get (or create) DataUrl
    #

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

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

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

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

    dataSource.dataStore = blockedBinaryMatrix

    return blockedBinaryMatrix
Beispiel #2
0
def getRefExpFromOldExpType(project,expType):

  refExperiment = None
  
  if oldToNewExpDict.has_key(expType):
    (expPrototypeName,refExpName) = oldToNewExpDict[expType]
    
    setCurrentStore(project,'ChemElementStore')
        
    expPrototype = project.findFirstNmrExpPrototype(name = expPrototypeName)
    
    if expPrototype:
      refExperiment = expPrototype.findFirstRefExperiment(name = refExpName)

  return refExperiment
Beispiel #3
0
    def __init__(self, parent, project, numDim=None, topText=None, expName=''):

        self.parent = parent
        self.project = project
        self.numDim = numDim
        self.topText = topText
        self.skip = 1
        self.expName = expName

        setCurrentStore(project, 'ChemElementStore')

        TemporaryBasePopup.__init__(self,
                                    parent=parent,
                                    title="Project '%s': " % project.name +
                                    'Create Experiment',
                                    modal=False,
                                    transient=True)
Beispiel #4
0
import Tkinter

from memops.api import Implementation
from memops.gui.Button import Button
from memops.gui.MessageReporter import showInfo

from ccp.general.Util import setCurrentStore
from ccp.gui.ChemCompFrame import ChemCompFrame
from ccp.gui.ChemCompEditor import ChemCompEditPopup

from pdbe.chemComp.Constants import editChemCompDataDir

if (__name__ == '__main__'):

    project = Implementation.MemopsRoot(name='edit')
    setCurrentStore(project, 'ChemElementStore')

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

    root.grid_rowconfigure(0, weight=1)
    root.grid_columnconfigure(0, weight=1)

    frame = ChemCompFrame(
        root, project,
        chemCompEntries=('ChemComp', ))  #path = editChemCompDataDir,
    frame.grid(sticky=Tkinter.NSEW)

    def getSelected():

        chemComp = frame.getSelectedChemComp()
Beispiel #5
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)()
Beispiel #6
0
def findDataStoringFromFilepath(project,
                                fullFilePath,
                                preferDataUrls=None,
                                dataLocationStore=None,
                                keepDirectories=1):
    """ Get DataUrl and relative filePath from normalised absolute filePath
  Uses heuristics to select compatible DataUrl from existing ones.
  sisterObjects is a collection of objects with a dataStore link - 
  DataUrls in use for sisterObjects are given preference in the
  heuristics.
  uses dataLocationStore or current dataLocationStore
  If no compatible DataUrl is found the routine returns dataUrl None
  and the file name plus the lowest keepDirectories directories 
  as the filePath
  """
    # NB fullFilePath *must* be absolute her for code to work properly
    #
    if not os.path.isabs(fullFilePath):
        raise ApiError(
            "findDataStoringFromFilepath called with non-absolute file name %s"
            % fullFilePath)

    # get DataLocationStore
    if not dataLocationStore:
        setCurrentStore(project, 'DataLocationStore')
        dataLocationStore = project.currentDataLocationStore

    # get DataUrl that match fullFilePath
    dataUrls = []
    for dataUrl in dataLocationStore.dataUrls:
        dirPath = uniIo.normalisePath(dataUrl.url.path)
        if fullFilePath.startswith(dirPath):
            lenPath = len(dirPath)
            ss = fullFilePath
            while len(ss) > lenPath:
                ss, junk = uniIo.splitPath(ss)
            if ss == dirPath:
                # DataUrl path matches file path
                dataUrls.append(dataUrl)

    # process result
    if dataUrls:
        if preferDataUrls:
            # look for DataUrls that are in use with related objects
            ll = [x for x in dataUrls if x in preferDataUrls]
            if ll:
                dataUrls = ll

        if len(dataUrls) == 1:
            # only one DataUrl - use it
            dataUrl = dataUrls[0]
        else:
            # use DataUrl with longest path
            ll = [(len(dataUrl.url.path), dataUrl) for dataUrl in dataUrls]
            ll.sort()
            dataUrl = ll[-1][1]

        # get filePath
        ss = uniIo.joinPath(dataUrl.url.path,
                            '')  # removes file separator from end
        filePath = fullFilePath[len(ss) + 1:]

    else:
        dataUrl = None
        ll = []
        ss = fullFilePath
        for dummy in range(keepDirectories + 1):
            ss, name = os.path.split(ss)
            ll.append(name)
        ll.reverse()
        filePath = uniIo.joinPath(*ll)

    #
    return (dataUrl, filePath)