Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finalized support for Docker. #37

Merged
merged 2 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/Release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,14 @@ jobs:
with:
src : dftbplus_step
secrets: inherit

docker:
name: Docker
needs: release
uses: molssi-seamm/devops/.github/workflows/Docker.yaml@main
with:
image : molssi-seamm/seamm-dftbplus
description: A DFTB+ executable packaged for use with SEAMM or standalone
# Can limit platforms, e.g., linux/amd64, linux/arm64
# platforms: linux/amd64
secrets: inherit
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
=======
History
=======
2024.4.24 -- Finalized support for Docker containers
* Fixed issues and tested running in containers.
* Add CI to make a Docker image for DFTB+
* Fixed issue with changes in input for DFTB+: CalculateGradients has become
PrintGradients it seems.

2024.1.18 -- Support for running in containers and writing input only.
* Added new property: scaled dipole.
* Added option to write the input file and not run DFTB+
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MODULE := dftbplus_step
.PHONY: help clean clean-build clean-docs clean-pyc clean-test lint format typing test
.PHONY: dependencies test-all coverage html docs servedocs release check-release
.PHONY: dist install uninstall
.PHONY: dist install uninstall image uninstall-image
.DEFAULT_GOAL := help

define BROWSER_PYSCRIPT
Expand Down Expand Up @@ -104,3 +104,9 @@ install: uninstall ## install the package to the active Python's site-packages

uninstall: clean ## uninstall the package
pip uninstall --yes $(MODULE)

image: uninstall-image ## Make the Docker image
cd devtools/docker && docker image build -t ghcr.io/molssi-seamm/seamm-dftbplus:latest .

uninstall-image: ## Remove the docker image
docker image rm --force ghcr.io/molssi-seamm/seamm-dftbplus:latest
19 changes: 19 additions & 0 deletions devtools/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM molssi/mamba141

LABEL org.opencontainers.image.authors="psaxe@molssi.org"

COPY ./environment.yml /root/environment.yml

RUN mamba env update -f /root/environment.yml

RUN apt-get install -qy curl

RUN mkdir /root/Parameters \
&& cd /root/Parameters \
&& curl 'https://dftb.org/fileadmin/DFTB/public/slako-unpacked.tar.xz' -o slako-unpacked.tar.xz \
&& tar -x -o -p -f slako-unpacked.tar.xz \
&& chmod -R go+rX . \
&& rm slako-unpacked.tar.xz

WORKDIR /home
CMD ["dftb+"]
10 changes: 10 additions & 0 deletions devtools/docker/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: base
channels:
- conda-forge
dependencies:
- python
# Executables, etc.
- dftbplus
- dftbplus-tools
- dftbplus-python

58 changes: 11 additions & 47 deletions dftbplus_step/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ def model(self):
def model(self, value):
self.parent.model = value

@property
def exe_config(self):
"""The configuration for the DFTB+ executable."""
return self.parent.exe_config

def band_structure(
self, input_path, sym_points, sym_names, Efermi=[0.0, 0.0], DOS=None
):
Expand Down Expand Up @@ -158,13 +163,6 @@ def create_band_structure_data(
full_config.read(ini_dir / "dftbplus.ini")

executor = self.parent.flowchart.executor
executor_type = executor.name
if executor_type not in full_config:
raise RuntimeError(
f"No section for '{executor_type}' in DFTB+ ini file "
f"({ini_dir / 'dftbplus.ini'})"
)
config = dict(full_config.items(executor_type))

if spin_polarized:
cmd = ["dp_bands", "-s", input_path, "band"]
Expand All @@ -173,7 +171,7 @@ def create_band_structure_data(

result = executor.run(
cmd=cmd,
config=config,
config=self.exe_config,
directory=self.directory,
files={},
return_files=["*"],
Expand Down Expand Up @@ -271,34 +269,16 @@ def create_dos_data(self, input_path, Efermi=[0.0]):

logger.info("Preparing DOS")

seamm_options = self.parent.global_options

# Total DOS
executor = self.parent.flowchart.executor

# Read configuration file for DFTB+
ini_dir = Path(seamm_options["root"]).expanduser()
full_config = configparser.ConfigParser()
full_config.read(ini_dir / "dftbplus.ini")
executor_type = executor.name
if executor_type not in full_config:
raise RuntimeError(
f"No section for '{executor_type}' in DFTB+ ini file "
f"({ini_dir / 'dftbplus.ini'})"
)
config = dict(full_config.items(executor_type))

result = executor.run(
cmd=[
"dp_dos",
str(input_path),
"dos_total.dat",
">",
"DOS.out",
"2>",
"dos_stderr.txt",
],
config=config,
config=self.exe_config,
directory=self.directory,
files={},
return_files=["*"],
Expand Down Expand Up @@ -369,12 +349,8 @@ def create_dos_data(self, input_path, Efermi=[0.0]):
"-w",
str(path),
str(out),
">",
"DOS.out",
"2>",
"dos_stderr.txt",
],
config=config,
config=self.exe_config,
directory=self.directory,
files={},
return_files=["*"],
Expand Down Expand Up @@ -788,26 +764,14 @@ def run(self, current_input):
"results.tag",
"*.xml",
"eigenvec.bin",
] # yapf: disable
]

# Run the calculation
executor = self.parent.flowchart.executor

# Read configuration file for DFTB+
ini_dir = Path(seamm_options["root"]).expanduser()
full_config = configparser.ConfigParser()
full_config.read(ini_dir / "dftbplus.ini")
executor_type = executor.name
if executor_type not in full_config:
raise RuntimeError(
f"No section for '{executor_type}' in DFTB+ ini file "
f"({ini_dir / 'dftbplus.ini'})"
)
config = dict(full_config.items(executor_type))

result = executor.run(
cmd=["{code}", ">", "DFTB+.out", "2>", "stderr.txt"],
config=config,
config=self.exe_config,
directory=self.directory,
files=files,
return_files=return_files,
Expand All @@ -816,7 +780,7 @@ def run(self, current_input):
env=env,
)

if result is None:
if not result:
logger.error("There was an error running DFTB+")
return None

Expand Down
2 changes: 1 addition & 1 deletion dftbplus_step/choose_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_input(self):

# Get the metadata for the Slater-Koster parameters
metadata = self.parent._metadata
slako_dir = Path(self.parent.options["slako_dir"]).expanduser()
slako_dir = Path(self.exe_config["slako-dir"]).expanduser()

# Create the directory
directory = Path(self.directory)
Expand Down
23 changes: 0 additions & 23 deletions dftbplus_step/data/configuration.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@
[dftbplus-step]

# Information about where/how the executables are installed
# installation may be 'user', 'conda' or 'module'. If a module is
# specified it will be loaded and those executables used. In this
# case, any path specified using dftbplus-path will be ignored.

installation =
conda-environment =
modules =

# The path to the executable. Can be empty or not present, in which
# case the default PATH is used. If a path is given, dftb+
# from this location will be used.
#
# Ignored if a module is used. The default is to use the PATH
# environment variable.

dftbplus-path =

# The path to the Slater-Koster functions

slako-dir =

# Whether to use MPI to run parallel

# use-mpi = False
Expand Down
80 changes: 80 additions & 0 deletions dftbplus_step/data/dftbplus.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Configuration options for how to run DFTB+

[docker]
# The code to use. This may maybe more than just the name of the code, and variables in
# braces {} will be expanded. For example:
# code = mpiexec -np {NTASKS} lmp_mpi
# would expand {NTASKS} to the number of tasks and run the command

code = dftb+

# The name and location of the Docker container to use, optionally with the version

container = ghcr.io/molssi-seamm/seamm-dftbplus:{version}

# In addition, you can specify the platform to use. This is useful on e.g. Macs with
# app silicon (M1, M3...) where the default platform is linux/arm64 but some containers
# are only available for linux/amd64.

# platform = linux/amd64

# The path to the Slater-Koster functions

slako-dir = /root/Parameters/slako


[local]
# The type of local installation to use. Options are:
# conda: Use a conda environment
# modules: Use the modules system
# local: Use a local installation
# docker: Use a Docker container
# By default SEAMM installs DFTB+ using conda.

installation = conda

# The command line to use, which should start with the executable followed by any options.
# Variables in braces {} will be expanded. For example:
#
# code = mpiexec -np {NTASKS} lmp_mpi
#
# would expand {NTASKS} to the number of tasks and run the command.
# For a 'local' installation, the command line should include the full path to the
# executable or it should be in the path.

code = dftb+

######################### conda section ############################
# The full path to the conda executable:

# conda =

# The Conda environment to use. This is either the name or full path.

conda-environment = seamm-dftbplus

######################### modules section ############################
# The modules to load to run DFTB+, as a list of strings.
# For example, to load the modules dftbplus and openmpi, you would use:
# modules = dftbplus openmpi

# modules =

######################### local section ############################
# The full path to the DFTB+ executable should be in the 'code' option.

######################### docker section ############################
# The name and location of the Docker container to use, optionally with the version.
# {version} will be expanded to the version of the plug-in.

# container = ghcr.io/molssi-seamm/seamm-dftbplus:{version}

# In addition, you can specify the platform to use. This is useful on e.g. Macs with
# app silicon (M1, M3...) where the default platform is linux/arm64 but some containers
# are only available for linux/amd64.

# platform = linux/amd64

# The path to the Slater-Koster functions

slako-dir = ~/SEAMM/Parameters/slako
Loading
Loading