File: loader.py

package info (click to toggle)
kineticstools 0.6.1%2Bgit20220223.1326a4d%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 22,188 kB
  • sloc: python: 3,508; makefile: 200; ansic: 104; sh: 55; xml: 19
file content (62 lines) | stat: -rw-r--r-- 2,118 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""Basic functional stuff, I guess.
"""
import logging
import os

LOG = logging.getLogger(__name__)


def getIpdModelFilename(ipdModel, majorityChem, paramsPath):
    """
    ipdModel: str
    majorityChem: str
    """
    # In order of precedence they are:
    # 1. Explicit path passed to --ipdModel
    # 2. In-order through each directory listed in --paramsPath

    if ipdModel:
        LOG.info("Using passed-in kinetics model: {!r}".format(ipdModel))
        return ipdModel

    if majorityChem == 'unknown':
        msg = "Chemistry cannot be identified---cannot perform kinetic analysis"
        LOG.error(msg)
        raise Exception(msg)

    # Route any pre-Kiwi / pre-SSB Sequel chemistries to Seabiscuit training
    if majorityChem.startswith("S/P1") or majorityChem.startswith("S/P2"):
        majorityChem = "SP2-C2"
    # Route any post-SSB Sequel chemistries to Kiwi training (for now)
    elif majorityChem.startswith("S/"):
        majorityChem = "SP3-C3"

    # '/' is not a valid character in a file, unescaped--remove it
    majorityChem = majorityChem.replace("/", "")

    # go through each paramsPath in-order, checking if the model exists there
    # or no
    for paramPath in paramsPath:
        ipdModel = os.path.join(paramPath, majorityChem + ".npz.gz")
        if os.path.isfile(ipdModel):
            LOG.info(
                "Using chemistry-matched kinetics model: {!r}".format(ipdModel))
            return ipdModel

    msg = "No kinetics model available for this chemistry ({!r}) on paramsPath {!r}".format(
        ipdModel, paramsPath)
    LOG.error(msg)
    raise Exception(msg)


def getResourcePathSpec(default_dir):
    """Create list of [${SMRT_CHEMISTRY_BUNDLE_DIR}/kineticsTools, {default_dir}].
    Return colon-separated string.
    """
    pths = []
    smrtChemBundlePath = os.environ.get("SMRT_CHEMISTRY_BUNDLE_DIR", None)
    if smrtChemBundlePath:
        LOG.info("found SMRT_CHEMISTRY_BUNDLE_DIR, prepending to default paramsPath")
        pths.append(os.path.join(smrtChemBundlePath, "kineticsTools"))
    pths.append(default_dir)
    return ':'.join(pths)