You are here: Home V2 Software Software Tutorials Python API Course Top-Level Projects

Top-Level Projects

How to create, load and save the top-level MemopsRoot object that contains all project data

Introduction

All of the data that interacts together within one project is contained by the top-level MemopsRoot object. This project object itself contains no scientific information, but only links to all of the other objects that are under its administration.  In the Python XML implementation the MemopsRoot object corresponds to its own XML file. The XML files for all objects are divided according to the package of the object. Sometimes a package will be represented by only a single XML file (e.g. for MemopsRoot or NmrProject data), and in other instances there are multiple XML files, e.g. for StructureEnsembles; where one would not wish to load all structures at the same time.

Note that the following examples assume that Python is set to use the CCPN directories for its imports. Under a LINUX/UNIX system this usually involves setting the $PYTHONPATH environment variable to $CCPN_HOME/ccpnmr2.1/python

Creating a New Project

To create a new project we must first import the MemopsRoot object from the Implementation package:

from memops.api.Implementation import MemopsRoot

Next, to create an empty project, issue something similar to the following, substituting your desired project name (without spaces):

rootProject = MemopsRoot(name='MyProjectName')

Your root project object is now ready to contain all other data. For example we could go on to generate an NMR sub-project using our new MemopsRoot object:

name = rootProject.name
nmrProject = rootProject.newNmrProject(name=name)

Note that in the above example we access the name attribute of the root project and use the same name for the NMR sub-project.

Loading an Existing Project

To load an existing project from file, import the load function from the I/O module and apply this to the name of the directory that contains the project XML data:

from memops.general.Io import loadProject

projectDirectory = '/home/user/myProjName'

rootProject = loadProject(projectDirectory)

In this instance the location of the project is specified with a Python string containing the absolute path of the project directory (which is almost always named after the project). This location is not the location of MemopsRoot XML.

Saving a Project

To save a modified project in the previously saved location simply issue:

rootProject.saveModified()

Note that the .save() method of MemopsRoot only saves the MemopsRoot XML and is thus not relevant for saving the entire contents of the project.

To save a brand new project or a project in a new location (or with a new name) a save function from the I/O module can be used:

from memops.general.Io import saveProject

targetDir = '/home/user/'
projectName = 'newProjectName'

saveProject(rootProject, targetDir, projectName)

Note that this will create a sub-directory (containing XML files) named for the project within the target directory.