ccpnmodel.ccpncore.lib package



ccpnmodel.ccpncore.lib.ApiPath module

API (data storage) level path and I/O handling utilities

ccpnmodel.ccpncore.lib.ApiPath.addCcpnDirectorySuffix(path: str) str[source]

Add ccpn directory suffix (‘.ccpn’ to path, unless present already


Input: project Output: Boolean - True if all loaded TopObjects exist in storage

ccpnmodel.ccpncore.lib.ApiPath.doesRepositoryContainProject(repositoryPath, projectName=None)[source]

Does repositoryPath contain project with specified projectName (or default projectName if not specified)?

ccpnmodel.ccpncore.lib.ApiPath.findTopObjectPath(repositoryPath, topObject)[source]

Get topObject absolute file path given the repositoryPath, where topObject can be of class MemopsRoot or TopObject.

Will find an existing file fitting the TopObject ID. If none is found returns default file name


Get implementation directory from the repositoryPath


Get the possible project files given the repositoryPath

ccpnmodel.ccpncore.lib.ApiPath.getProjectFile(repositoryPath, projectName=None)[source]

Get project file given the repositoryPath and optionally the projectName (if none given then determined from repositoryPath)

ccpnmodel.ccpncore.lib.ApiPath.getTopObjIdFromFileName(fileName, mustBeMultipart=None)[source]

Get project name or TopObject guid from file name (relative or absolute) Note: TopObject ID is constrained to not need decoding


Get topObject file name (not path) where topObject can be of class MemopsRoot or TopObject


Get topObject (absolute) path where topObject can be of class MemopsRoot or TopObject

ccpnmodel.ccpncore.lib.ApiPath.removeCcpnDirectorySuffix(path: str) str[source]

Remove ccpn directory suffix (‘.ccpn’) from path, if present

ccpnmodel.ccpncore.lib.Constants module

Definition of program-level constants

ccpnmodel.ccpncore.lib.Conversion module

======================COPYRIGHT/LICENSE START========================== Data compatibility handling

Copyright (C) 2007-2014 Rasmus Fogh (CCPN project)

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

A copy of this license can be found in ../../../../license/LGPL.license.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

======================COPYRIGHT/LICENSE END============================

To obtain more information about this code:

__licence__ = (“CCPN licence. See”,

“or ccpnmodel.ccpncore.memops.Credits.CcpnLicense for licence text”)

__reference__ = (“For publications, please use reference from”,

“or ccpnmodel.ccpncore.memops.Credits.CcpNmrReference”)

#========================================================================================= # Last code modification #========================================================================================= __modifiedBy__ = “$modifiedBy: CCPN $” __dateModified__ = “$dateModified: 2017-07-07 16:33:09 +0100 (Fri, July 07, 2017) $” __version__ = “$Revision: 3.0.0 $” #========================================================================================= # Created #========================================================================================= __author__ = “$Author: rhf22 $” __date__ = “$Date: 2017-04-07 10:28:48 +0000 (Fri, April 07, 2017) $” #========================================================================================= # Start of code #=========================================================================================

If you are using this software for academic purposes, we suggest quoting the following reference:

===========================REFERENCE START============================= Rasmus H. Fogh, Wayne Boucher, Wim F. Vranken, Anne Pajon, Tim J. Stevens, T.N. Bhat, John Westbrook, John M.C. Ionides and Ernest D. Laue (2005). A framework for scientific data modeling and automated software development. Bioinformatics 21, 1678-1684. ===========================REFERENCE END===============================

ccpnmodel.ccpncore.lib.Conversion.getConversionInfo(fromVersionString, toVersionString)[source]

get dictionary with elemsTreatedAsOld, extraMapChanges function and correctData function to go from fromVersion to toVersion

redirect certain NmrExpPrototype links to other experiments

ccpnmodel.ccpncore.lib.CopyData module

API (data storage) level object tree copying

ccpnmodel.ccpncore.lib.CopyData.copySubTree(sourceObj, newParent, maySkipCrosslinks: bool = False, topObjectParameters: Optional[dict] = None, objectMap: Optional[dict] = None)[source]

Copy an api object and all its descendants within or between projects

  • sourceObj – CCPN api object to be copied

  • newParent – parent for the copied object

  • maySkipCrosslinks (bool) – Whether to skip crosslinks if copying them it not possible.

  • topObjectParameters (dict) – parameters to be passed to copy of source object

  • objectMap (dict) – oldObject:newObject mappings to use as targets for crosslinks


copy of source object

(Parts of) crosslinks to objects within the subtree are copied to links to the new object copies; (Parts of) crosslinks to objects not within the subtree are copied to links to the old objects, provided this can be done without cutting pre-existing links. If the above will not work and maySkipCrosslinks is True, the routine tries to set the crosslink using only the objects within the subtree. If none of the above works, an error is thrown.

The key,val pairs in the topObjectParameters dictionary are passed to the top object constructor, and the pre-existing values in the sourceObj are ignored. This can be used to set new values for the keys of sourceObj.

If the top object has ‘serial’ as the key and no valid serial is passed in topObjectParameters, the routine will set the serial to the next available value.

Note that the function first builds all objects, then connects crosslinks, then connects parent-to-child links. Finally all notifiers are called but in random order. If there is an error the routine tries to delete all created objects before re-raising the original error. A failed function call may consume serial numbers if the key of the sourceObj is ‘serial’. Also, there is a relatively high bug risk, as is always the case with functions that have to clean up after an error.


ccpnmodel.ccpncore.lib.MergeObjects module

MOdule for generic merging of data model objects Transfers simple and link attributes from the source object to target object Does not transfer derived, automatic or immutable attributes Links will be transferred where possible Where necessary the Api is bypassed

Logical analysis and design by R.H. Fogh

Coding and testing by T.J. Stevens

Definitions: Objects targetObj and sourceObj of class O link O.a (a) to class A, with backlink A.o ( o)

A note on checks: Where the API is bypassed, the function does validity checks at each step, and rolls back the last step if the checks fail. The checks are done on sourceObj, targetObj, objects on the other end of links, and the parents of the latter. The check on parents is done because this includes a check on the keys of the children - the merge cannot change the keys of either source or target, but can change the key of linked-to objects.

ccpnmodel.ccpncore.lib.MergeObjects.mergeObjects(sourceObj, targetObj, _useV3Delete=False, _mergeFunc=None)[source]

Merges sourceObj into targetObj, deleting sourceObj. Attributes and links from sourceObj are added to targetObj provided 1) that they are not there already, and 2) that there is room.

WARNING this function bypasses the API.

WARNING Merging objects with child links or frozen links is NOT undoable

and undo stack is cleared

WARNING, integrated update operations, e.g. Chemical Shift averaging and notifiers are NOT reliably performed during merging and must be handled by the callign function

WARNING This function just might leave the data in an illegal state The function performs a number of checks for each individual change. If a check fails, the latest change is undone before the error exit, in an attempt to leave the data in a state that is legal. Note that only the latest change is undone - in case of error the data state will not be brought back to the state from before the execution of the command. Note that sourceObj is likely to be in an illegal state during execution, so that an error may well leave sourceObj in an illegal state. If this happens, deleting sourceObj may bring the data back to a legal state, and is unlikely to cause further problems. In spite of the checks, some objects (not limited to sourceObj and targetObj) may be left in an illegal state, even if no error is raised. It is recommended to use this function with caution, and to run checkAllValid after it has been used.

ccpnmodel.ccpncore.lib.Util module

API (data storage) level miscellaneous utilities


Get Api class from fully qualified (dot-separated) name


get configuration parameter, from reading configuration file

ccpnmodel.ccpncore.lib.V2Upgrade module

Mapping of Resonances and ResonancGroups in version 2 to new 4-string assignment style

ccpnmodel.ccpncore.lib.V2Upgrade.addOffsetResonanceGroup(addToGroup: ResonanceGroup, addGroup: ResonanceGroup, offset: int) bool[source]

Add addGroup as satellite to addToGroup with offset offset. Return True if successful

ccpnmodel.ccpncore.lib.V2Upgrade.findConnectedSpinSystems(spinSystem, delta=None)[source]

Find spin systems sequentially connected to the input one with given sequence offset.


Nmr.ResonanceGroup, Int .. describe:: Output



V2: find unique resonanceGroup linked as identical to teh input

ccpnmodel.ccpncore.lib.V2Upgrade.findSpinSystemStretch(resonanceGroup, excludedSpinSystems={})[source]

Find (one of the) longest sequential spin system stretch(es) containing resonanceGroup

Get any sequential spin system links (resonanceGroupProbs). An optional sequence offset may be specified.


Nmr.ResonanceGroup, Int


List of Nmr.ResonanceGroupProbs

ccpnmodel.ccpncore.lib.V2Upgrade.mapAssignedResonances(topObject, molSystem=None, chainMap=None)[source]

Make/extend {resonance:assignmentTuple} map in V2 for either Resonances or fixedResonances chainMap remaps chains to new ones with different chainCodes (for V2-V3 upgrade).

NB, does NOT use ResonanceGroup information

ccpnmodel.ccpncore.lib.V2Upgrade.mapResonanceGroupResidues(apiNmrProject, molSystem=None, chainMap=None) dict[source]

Map resonanceGroup:assignmentTuple for fully assigned ResonanceGroups


Map unassigned resonances for NmrConstraintStore

NBNB This must be done AFTER assignments and resonances are done, as it transfers teh assignment of the attached NmrProject resonance (if any) to the fixedResonance


V2: Get resonance name, starting with element type and adding @serial to impossible names


Upgrade ConstraintList from early V3 to newer V3 - this avoids redoing earlier function and anyway data must be copied to a new set of objects

Will also work if called on old-type V3 ConstraintLists (use only internally)

ccpnmodel.ccpncore.lib.updateHeader module