Source code for puffin.programs.serenity

# -*- coding: utf-8 -*-
__copyright__ = """This file is part of SCINE Puffin.
This code is licensed under the 3-clause BSD license.
Copyright ETH Zurich, Laboratory for Physical Chemistry, Reiher Group.
See LICENSE.txt for details
"""

import os
import subprocess
import sys
import git
from typing import List

from .program import Program
from puffin.config import Configuration


[docs]class Serenity(Program): """ Serenity -- installation and verification class """ def __init__(self, settings: dict): super().__init__(settings) def install(self, repo_dir: str, install_dir: str, ncores: int): if self.root: pass elif self.source: initial_dir = os.getcwd() # Handle repository if os.path.exists(repo_dir): repository = git.Repo(repo_dir) repository.remotes.origin.pull() repository.git.checkout(self.version) repository.remotes.origin.pull() else: repository = git.Repo.clone_from(self.source, repo_dir) repository.git.checkout(self.version) # Build from sources into <repo>/build and install build_dir = os.path.join(repo_dir, 'build') if build_dir and not os.path.exists(build_dir): os.makedirs(build_dir) os.chdir(build_dir) env = os.environ.copy() env["PATH"] = env["PATH"] + ":" + os.path.join(install_dir, 'bin') if "LD_LIBRARY_PATH" in env.keys(): env["LD_LIBRARY_PATH"] = env["LD_LIBRARY_PATH"] + ":" + os.path.join(install_dir, 'lib') else: env["LD_LIBRARY_PATH"] = os.path.join(install_dir, 'lib') env["LD_LIBRARY_PATH"] = env["LD_LIBRARY_PATH"] + ":" + os.path.join(install_dir, 'lib64') subprocess.run(['cmake', '-DCMAKE_BUILD_TYPE=Release', '-DSERENITY_SCINE_INTERFACE=ON', '-DSERENITY_PYTHON_BINDINGS=ON', '-DSERENITY_MARCH='+self.settings['march'], '-DSERENITY_ENABLE_TESTS=OFF', '-DCMAKE_INSTALL_PREFIX='+install_dir, '-DPYTHON_EXECUTABLE='+sys.executable, '..'], env=env) subprocess.run(['make', '-j'+str(ncores), 'install'], env=env) os.chdir(initial_dir) else: raise RuntimeError def check_install(self): raise NotImplementedError def setup_environment(self, config: Configuration, env_paths: dict, env_vars: dict): if self.root: env_paths["PATH"] = env_paths["PATH"] + ":" + os.path.join(self.root, 'bin') env_paths["LD_LIBRARY_PATH"] = env_paths["LD_LIBRARY_PATH"] + ":" + os.path.join(self.root, 'lib') env_vars["SERENITY_RESOURCES"] = os.path.join(self.root, 'data') env_vars["SERENITY_MEMORY"] = str(float(config.resources()['memory'])*1024) env_vars["OMP_NUM_THREADS"] = str(config.resources()['cores']) elif self.source: env_vars["SERENITY_RESOURCES"] = os.path.join(config.daemon()['software_dir'], 'install', 'data') env_vars["SERENITY_MEMORY"] = str(float(config.resources()['memory'])*1024) env_vars["OMP_NUM_THREADS"] = str(config.resources()['cores']) else: raise RuntimeError def available_models(self) -> List[str]: return ['DFT', 'HF']