pyiron / pyiron_atomistics

pyiron_atomistics - an integrated development environment (IDE) for atomistic simulation in computational materials science.
https://pyiron-atomistics.readthedocs.io
BSD 3-Clause "New" or "Revised" License
44 stars 15 forks source link

VASP: Implement get_input_file_dict() #1447

Closed jan-janssen closed 4 months ago

jan-janssen commented 4 months ago

The get_input_file_dict() returns a dictionary with the following structure:

{
    "files_to_create": {"file_name": "file_content_as_single_string"},
    "files_to_copy": {"file_name": "file_source"},
}

With this unification the write_input() function can be replace with a standardised function for all codes:

def write_input(self):
    """
    Call routines that generate the code specific input files
    Returns:
    """
    input_dict = self.get_input_file_dict()
    for file_name, content in input_dict["files_to_create"].items():
        with open(os.path.join(self.working_directory, file_name), "w") as f:
            f.writelines(content)
    for file_name, source in input_dict["files_to_copy"].items():
        shutil.copy(source, os.path.join(self.working_directory, file_name))
coveralls commented 4 months ago

Pull Request Test Coverage Report for Build 9444468421

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
pyiron_atomistics/vasp/potential.py 5 7 71.43%
pyiron_atomistics/vasp/base.py 22 27 81.48%
<!-- Total: 67 74 90.54% -->
Files with Coverage Reduction New Missed Lines %
pyiron_atomistics/vasp/structure.py 4 97.98%
pyiron_atomistics/vasp/base.py 72 66.36%
<!-- Total: 76 -->
Totals Coverage Status
Change from base Build 9438715818: -0.02%
Covered Lines: 10680
Relevant Lines: 15007

💛 - Coveralls
coveralls commented 4 months ago

Pull Request Test Coverage Report for Build 9444530779

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
pyiron_atomistics/vasp/potential.py 5 7 71.43%
pyiron_atomistics/vasp/base.py 16 21 76.19%
<!-- Total: 61 68 89.71% -->
Totals Coverage Status
Change from base Build 9438715818: -0.02%
Covered Lines: 10680
Relevant Lines: 15007

💛 - Coveralls
coveralls commented 4 months ago

Pull Request Test Coverage Report for Build 9471869531

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
pyiron_atomistics/vasp/base.py 23 25 92.0%
pyiron_atomistics/vasp/potential.py 5 7 71.43%
<!-- Total: 68 72 94.44% -->
Files with Coverage Reduction New Missed Lines %
pyiron_atomistics/dft/bader.py 4 92.73%
pyiron_atomistics/vasp/base.py 214 66.03%
<!-- Total: 218 -->
Totals Coverage Status
Change from base Build 9438715818: -0.02%
Covered Lines: 10681
Relevant Lines: 15009

💛 - Coveralls
jan-janssen commented 4 months ago

@samwaseda As we already discussed a very similar pull request for LAMMPS https://github.com/pyiron/pyiron_atomistics/pull/1446 I just added you as an additional reviewer here.

coveralls commented 4 months ago

Pull Request Test Coverage Report for Build 9472795099

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
pyiron_atomistics/vasp/base.py 23 25 92.0%
pyiron_atomistics/vasp/potential.py 5 7 71.43%
<!-- Total: 68 72 94.44% -->
Files with Coverage Reduction New Missed Lines %
pyiron_atomistics/dft/bader.py 4 92.73%
pyiron_atomistics/vasp/base.py 214 66.03%
<!-- Total: 218 -->
Totals Coverage Status
Change from base Build 9438715818: -0.02%
Covered Lines: 10681
Relevant Lines: 15009

💛 - Coveralls
coveralls commented 4 months ago

Pull Request Test Coverage Report for Build 9476641099

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
pyiron_atomistics/vasp/base.py 23 25 92.0%
pyiron_atomistics/vasp/potential.py 5 7 71.43%
<!-- Total: 68 72 94.44% -->
Files with Coverage Reduction New Missed Lines %
pyiron_atomistics/vasp/base.py 3 66.03%
<!-- Total: 3 -->
Totals Coverage Status
Change from base Build 9450521916: -0.02%
Covered Lines: 10681
Relevant Lines: 15009

💛 - Coveralls
coveralls commented 4 months ago

Pull Request Test Coverage Report for Build 9476744849

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
pyiron_atomistics/vasp/base.py 23 25 92.0%
pyiron_atomistics/vasp/potential.py 5 7 71.43%
<!-- Total: 68 72 94.44% -->
Files with Coverage Reduction New Missed Lines %
pyiron_atomistics/vasp/base.py 3 66.03%
<!-- Total: 3 -->
Totals Coverage Status
Change from base Build 9450521916: -0.02%
Covered Lines: 10681
Relevant Lines: 15009

💛 - Coveralls
coveralls commented 4 months ago

Pull Request Test Coverage Report for Build 9477144844

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
pyiron_atomistics/vasp/potential.py 5 7 71.43%
pyiron_atomistics/vasp/base.py 17 22 77.27%
<!-- Total: 62 69 89.86% -->
Totals Coverage Status
Change from base Build 9477094720: -0.02%
Covered Lines: 10695
Relevant Lines: 15025

💛 - Coveralls
jan-janssen commented 4 months ago

Define a calculate() function which can be submitted using an pympipool.Executor:

from pympipool import Executor
import os
import posixpath
import shutil
import subprocess
from pyiron_atomistics import Project
from pyiron_atomistics.vasp.output import parse_vasp_output

def calculate_vasp(working_directory, input_file_dict, executable_dict, collect_output_kwargs):
    os.makedirs(working_directory, exist_ok=True)
    for file_name, content in input_file_dict["files_to_create"].items():
        with open(os.path.join(working_directory, file_name), "w") as f:
            f.writelines(content)
    for file_name, source in input_file_dict["files_to_copy"].items():
        shutil.copy(source, os.path.join(working_directory, file_name))
    _ = subprocess.run(
        executable_dict["command"],
        cwd=working_directory,
        shell=executable_dict["shell"],
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        universal_newlines=True,
        check=True,
    )
    return parse_vasp_output(
        working_directory=working_directory,
        **collect_output_kwargs,
    )

pr = Project("test")
pr.remove_jobs(recursive=True, silently=True)
job = pr.create.job.Vasp("vasp")
job.structure = pr.create.structure.ase.bulk("Al", cubic=True)
job.validate_ready_to_run()

executable, shell = job.executable.get_input_for_subprocess_call(
    cores=job.server.cores, threads=job.server.threads, gpus=job.server.gpus
)
with Executor(backend="mpi") as exe:
    future = exe.submit(
        calculate_vasp, 
        working_directory="tmp", 
        input_file_dict=job.get_input_file_dict(), 
        executable_dict={
            "command": executable,
            "shell": shell,
        }, 
        collect_output_kwargs={
            "sorted_indices": job.sorted_indices,
            "structure": job.structure,
        },
    )
    output_dict = future.result()

job._python_only_job = True
job.save()
job._store_output(output_dict=output_dict)

job_reload = pr.load(job.job_name)
print(job_reload.output.energy_pot)
jan-janssen commented 4 months ago

Waiting for https://github.com/pyiron/pyiron_base/pull/1472

coveralls commented 4 months ago

Pull Request Test Coverage Report for Build 9609405373

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
pyiron_atomistics/vasp/potential.py 5 7 71.43%
pyiron_atomistics/vasp/base.py 22 26 84.62%
<!-- Total: 67 73 91.78% -->
Files with Coverage Reduction New Missed Lines %
pyiron_atomistics/vasp/base.py 17 61.73%
pyiron_atomistics/lammps/output.py 21 87.18%
pyiron_atomistics/lammps/interactive.py 22 45.59%
pyiron_atomistics/lammps/base.py 73 79.85%
<!-- Total: 133 -->
Totals Coverage Status
Change from base Build 9609409415: -0.1%
Covered Lines: 10676
Relevant Lines: 15023

💛 - Coveralls
coveralls commented 4 months ago

Pull Request Test Coverage Report for Build 9609413711

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
pyiron_atomistics/vasp/potential.py 5 7 71.43%
pyiron_atomistics/vasp/base.py 22 26 84.62%
<!-- Total: 67 73 91.78% -->
Files with Coverage Reduction New Missed Lines %
pyiron_atomistics/vasp/base.py 17 61.73%
<!-- Total: 17 -->
Totals Coverage Status
Change from base Build 9609409415: -0.1%
Covered Lines: 10677
Relevant Lines: 15026

💛 - Coveralls