-
Notifications
You must be signed in to change notification settings - Fork 111
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
Add JDFTx jobs.py to run JDFTx using atomate2/jobflow #349
Merged
Merged
Changes from 3 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f3bac9d
Added JDFTx jobs.py script needed to run JDFTx using Custodian Job.
soge8904 baedd28
Added __init__.py
soge8904 0e23c63
pre-commit auto-fixes
pre-commit-ci[bot] 82d1adb
will need to make this more flexible
soge8904 a688688
Changed input file name to init.in.
soge8904 4a44a83
Finished tests for jobs.py + changed the terminate method
soge8904 8fc5b50
changed cmd.split to schlex.split + made pre-commit changes + created…
soge8904 6112996
Merge branch 'master' into jdftx
soge8904 f26713f
Merge pull request #1 from soge8904/jdftx
soge8904 7775f1d
pre-commit auto-fixes
pre-commit-ci[bot] 51ef781
Merge branch 'materialsproject:master' into master
soge8904 b69cacb
pre-commit auto-fixes
pre-commit-ci[bot] 2628e94
undo accidental chage to vasp file + added string as argument into sc…
soge8904 13a42b0
Merge branch 'jdftx' of https://github.com/soge8904/custodian into jdftx
soge8904 8202dbd
Merge pull request #2 from soge8904/jdftx
soge8904 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
""" | ||
This package implements various JDFTx Jobs and Error Handlers. | ||
Used Cp2kJob developed by Nick Winner as a template. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
"""This module implements basic kinds of jobs for JDFTx runs.""" | ||
|
||
import logging | ||
import os | ||
import subprocess | ||
|
||
from custodian.custodian import Job | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class JDFTxJob(Job): | ||
"""A basic JDFTx job. Runs whatever is in the working directory.""" | ||
|
||
# If testing, use something like: | ||
# job = JDFTxJob() | ||
# job.run() # assumes input files already written to directory | ||
|
||
def __init__( | ||
self, | ||
jdftx_cmd, | ||
input_file="jdftx.in", | ||
output_file="jdftx.out", | ||
stderr_file="std_err.txt", | ||
) -> None: | ||
""" | ||
This constructor is necessarily complex due to the need for | ||
flexibility. For standard kinds of runs, it's often better to use one | ||
of the static constructors. The defaults are usually fine too. | ||
|
||
Args: | ||
jdftx_cmd (str): Command to run JDFTx as a string. | ||
input_file (str): Name of the file to use as input to JDFTx | ||
executable. Defaults to "input.in" | ||
output_file (str): Name of file to direct standard out to. | ||
Defaults to "jdftx.out". | ||
stderr_file (str): Name of file to direct standard error to. | ||
Defaults to "std_err.txt". | ||
""" | ||
self.jdftx_cmd = jdftx_cmd | ||
self.input_file = input_file | ||
self.output_file = output_file | ||
self.stderr_file = stderr_file | ||
|
||
def setup(self, directory="./") -> None: | ||
"""No setup required.""" | ||
|
||
def run(self, directory="./"): | ||
""" | ||
Perform the actual JDFTx run. | ||
|
||
Returns: | ||
------- | ||
(subprocess.Popen) Used for monitoring. | ||
""" | ||
cmd = self.jdftx_cmd + " -i " + self.input_file + " -o " + self.output_file | ||
logger.info(f"Running {cmd}") | ||
with ( | ||
open(os.path.join(directory, self.output_file), "w") as f_std, | ||
open(os.path.join(directory, self.stderr_file), "w", buffering=1) as f_err, | ||
): | ||
# use line buffering for stderr | ||
return subprocess.run( | ||
cmd.split(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should prefer shlex.split() |
||
cwd=directory, | ||
stdout=f_std, | ||
stderr=f_err, | ||
shell=False, | ||
check=False, | ||
) | ||
|
||
def postprocess(self, directory="./") -> None: | ||
"""No post-processing required.""" | ||
|
||
def terminate(self, directory="./") -> None: | ||
"""Terminate JDFTx.""" | ||
# This will kill any running process with "jdftx" in the name, | ||
# this might have unintended consequences if running multiple jdftx processes | ||
# on the same node. | ||
for cmd in self.jdftx_cmd: | ||
if "jdftx" in cmd: | ||
try: | ||
os.system(f"killall {cmd}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See implementation of terminate() in VASP job to avoid killing all JDFTx processes when possible |
||
except Exception as e: | ||
print(f"Unexpected error occurred: {e}") | ||
raise |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can remove the note about the constructor being "complex", it doesn't seem to be complex. I believe this note is copy-pasted from another constructor that is complex