File tree Expand file tree Collapse file tree 4 files changed +80
-0
lines changed
notebooks/ccdc_notebook_utilities Expand file tree Collapse file tree 4 files changed +80
-0
lines changed Original file line number Diff line number Diff line change 1+ # Shared utilities
2+ This package contains shared functionality that is used in multiple notebooks
Original file line number Diff line number Diff line change 1+ #
2+ # This script can be used for any purpose without limitation subject to the
3+ # conditions at http://www.ccdc.cam.ac.uk/Community/Pages/Licences/v2.aspx
4+ #
5+ # This permission notice and the following statement of attribution must be
6+ # included in all copies or substantial portions of this script.
7+ #
8+ # 2022-05-17: created by Jason Cole, The Cambridge Crystallographic Data Centre
9+ #
10+ from .run_hermes import run_hermes
11+ from .create_logger import create_logger
Original file line number Diff line number Diff line change 1+ #
2+ # This script can be used for any purpose without limitation subject to the
3+ # conditions at http://www.ccdc.cam.ac.uk/Community/Pages/Licences/v2.aspx
4+ #
5+ # This permission notice and the following statement of attribution must be
6+ # included in all copies or substantial portions of this script.
7+ #
8+ # 2022-05-17: created by Jason Cole, The Cambridge Crystallographic Data Centre
9+ #
10+
11+ import logging
12+ from platform import platform
13+ import sys
14+ import ccdc .io
15+ import os
16+
17+ """
18+ From inside a notebook, create a logger and log starting information
19+ """
20+ def create_logger (verbose = True ):
21+ logger = logging .getLogger (__name__ )
22+ handler = logging .StreamHandler ()
23+ handler .setFormatter (logging .Formatter ('[%(asctime)s %(levelname)-7s] %(message)s' , datefmt = '%y-%m-%d %H:%M:%S' ))
24+ logger .addHandler (handler )
25+ logger .setLevel (logging .INFO )
26+
27+ if verbose :
28+ logger .info (f"""
29+ Platform: { platform ()}
30+
31+ Python exe: { sys .executable }
32+ Python version: { '.' .join (str (x ) for x in sys .version_info [:3 ])}
33+
34+ CSD version: { ccdc .io .csd_version ()}
35+ CSD directory: { ccdc .io .csd_directory ()}
36+ API version: { ccdc .__version__ }
37+
38+ CSDHOME: { os .environ .get ('CSDHOME' , 'Not set' )}
39+ CCDC_LICENSING_CONFIGURATION: { os .environ .get ('CCDC_LICENSING_CONFIGURATION' , 'Not set' )}
40+ """ )
41+ return logger
Original file line number Diff line number Diff line change 1+ #
2+ # This script can be used for any purpose without limitation subject to the
3+ # conditions at http://www.ccdc.cam.ac.uk/Community/Pages/Licences/v2.aspx
4+ #
5+ # This permission notice and the following statement of attribution must be
6+ # included in all copies or substantial portions of this script.
7+ #
8+ # 2022-05-17: created by Jason Cole, The Cambridge Crystallographic Data Centre
9+ #
10+
11+ from ccdc .io import csd_directory
12+ from pathlib import Path
13+ from platform import platform
14+ from subprocess import Popen
15+
16+ """
17+ From inside a notebook, run CCDC Hermes utility or fail if we cant find it. Assumes the
18+ software is installed alongside the data folder currently.
19+ """
20+ def run_hermes (* filenames ):
21+ try :
22+ hermes_dir = Path ( csd_directory () ) / '..' / '..' / 'ccdc-software' / 'hermes'
23+ hermes_exe = (hermes_dir / 'hermes.exe' if platform ().startswith ('Windows' ) else hermes_dir / 'hermes' ).as_posix ()
24+ status = Popen ([hermes_exe , * filenames ], creationflags = 0x00000008 )
25+ except Exception as e :
26+ print ( f"Couldnt run Hermes { e } " )
You can’t perform that action at this time.
0 commit comments