Source code for ccpn.AnalysisStructure.lib.runManagers.CyanaRunManager

"""
Cyana Run Manager
"""
#=========================================================================================
# Licence, Reference and Credits
#=========================================================================================
__copyright__ = "Copyright (C) CCPN project (https://www.ccpn.ac.uk) 2014 - 2022"
__credits__ = ("Ed Brooksbank, Joanna Fox, Victoria A Higman, Luca Mureddu, Eliza Płoskoń",
               "Timothy J Ragan, Brian O Smith, Gary S Thompson & Geerten W Vuister")
__licence__ = ("CCPN licence. See https://ccpn.ac.uk/software/licensing/")
__reference__ = ("Skinner, S.P., Fogh, R.H., Boucher, W., Ragan, T.J., Mureddu, L.G., & Vuister, G.W.",
                 "CcpNmr AnalysisAssign: a flexible platform for integrated NMR analysis",
                 "J.Biomol.Nmr (2016), 66, 111-124, http://doi.org/10.1007/s10858-016-0060-y")
#=========================================================================================
# Last code modification
#=========================================================================================
__modifiedBy__ = "$modifiedBy: Geerten Vuister $"
__dateModified__ = "$dateModified: 2022-03-11 15:07:06 +0000 (Fri, March 11, 2022) $"
__version__ = "$Revision: 3.1.0 $"
#=========================================================================================
# Created
#=========================================================================================
__author__ = "$Author: Geerten Vuister $"
__date__ = "$Date: 2022-03-09 16:04:57 +0000 (Thu, March 9, 2022) $"
#=========================================================================================
# Start of code
#=========================================================================================

import os
import shutil
import argparse
import string
import sys
import pathlib
import re

from pynmrstar import Entry, Saveframe, Loop
from datetime import datetime

from distutils.dir_util import copy_tree

from ccpn.util.traits.CcpNmrTraits import \
    Unicode, Dict, List, V3ObjectList, V3Object, Bool, CPath, Int
from ccpn.util.Logging import getLogger
from ccpn.util.Path import aPath, Path

from ccpn.AnalysisStructure.lib.runManagers.RunManagerABC import RunManagerABC
from ccpn.framework.Preferences import getPreferences, \
    XPLOR_NIH_PATH, TALOS_PATH, CYANA_PATH, ARIA_PATH

from ccpn.core.lib.ContextManagers import undoBlockWithoutSideBar, notificationEchoBlocking


[docs]class CyanaRunManager(RunManagerABC): """ Class that maintains Cyana structure calculation functionality """ _RUN_TYPE = 'cyana' # cyana-specific # program-defs; these are not saved to json # "redirect" the RunManagerABC definitions _EXECUTABLE1 = CYANA_PATH _cyanaPath = RunManagerABC._executable1 # just a better name # # program-defs; don't save these to json # _cyanaPath = CPath(allow_none=True, default_value=None).tag( # info='The path of the cyana executable; typically set from preferences', # saveToJson=False # ) def __init__(self, project, **kwds): """ :param project: the project instance """ super().__init__(project=project, **kwds) #TODO: check for minimal cyana version # if self._cyanaPath.exists(): # pass # getLogger().warning(f'Some message') # def restoreState(self, runPath=None): # """Restore the settings from json-file in directory runPath # (defaults to the directory defined by current settings). # # :param runPath: the path to the directory # """ # super().restoreState(runPath=runPath) # # patch to check if calculation was done; look for 'fold' files (or directory) # self.calculationDone = self.calculationDone or (len(list(self.runPath.glob('fold*'))) > 0) #-------------------------------------------------------------------------------
[docs] def setupCalculation(self) -> Path: """This sets up the xplor_nih structure calculation; :return The absolute path to the run directory """ logger = getLogger() if self._cyanaPath is None: raise RuntimeError('Undefined cyana path') # Create a new directory with a time stamp _runPath = self.fetchDirectory() # step 1; create the Nef input file _nefInputPath = self.writeNefInputFile() return _runPath
[docs] def processCalculation(self): """Process the resulting Cyana-generated files; """ if not self.setupDone: raise RuntimeError('Setup was not done') if not self.calculationDone: raise RuntimeError('Calculation was not done')
# do whatever is needed #------------------------------------------------------------------------------- # Helper code #------------------------------------------------------------------------------- def _writeCyanaScript(self, scriptPath=None) -> Path: """Generate (from template) and write a cyana-script :param scriptPath: optional relative path name for script :return The absolute path to script as a Path instance """ if scriptPath is not None: # optionally define a non-default relative path of the script; i.e. just the filename self.scriptPath = scriptPath _scriptPath = self.runPath / self.scriptPath with _scriptPath.open(mode='w') as fp: fp.write(self._getCyanaScript()) _scriptPath.chmod(0o755) return _scriptPath def _getCyanaScript(self): """:return The cyana script """ return f"""#!/bin/sh # script goes here # {self._cyanaPath} < something """