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

initial implementation of lammps support #114

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions mdbenchmark/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
"Parameter paths must be absolute. Only crude file checks are performed! "
"If you use the {} option make sure you use the GPU compatible NAMD module!"
)

LAMMPS_WARNING = (
"LAMMPS support is experimental."
"All input files must be in the same directory and have the same base name!"
"We hope you know what you're doing..."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"We hope you know what you're doing..."

)

def validate_name(ctx, param, name=None):
"""Validate that we are given a name argument."""
Expand Down Expand Up @@ -215,9 +219,11 @@ def generate(name, cpu, gpu, module, host, min_nodes, max_nodes, time, skip_vali
# click does the validation for us
template = utils.retrieve_host_template(host)

# Warn the user that NAMD support is still experimental.
# Warn the user that NAMD and LAMMPS support is still experimental.
if any(["namd" in m for m in module]):
console.warn(NAMD_WARNING, "--gpu")
if any(["lammps" in m for m in module]):
console.warn(LAMMPS_WARNING)

module = mdengines.normalize_modules(module, skip_validation)

Expand Down
7 changes: 4 additions & 3 deletions mdbenchmark/mdengines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

import six

from . import gromacs, namd
from . import gromacs, namd, lammps
from .. import console

SUPPORTED_ENGINES = {"gromacs": gromacs, "namd": namd}
SUPPORTED_ENGINES = {"gromacs": gromacs, "namd": namd, "lammps": lammps}


def detect_md_engine(modulename):
Expand Down Expand Up @@ -63,6 +63,7 @@ def prepare_module_name(module, skip_validation=False):
"--skip-validation",
"gromacs/dummy",
"namd/dummy",
"lammps/dummy"
)
console.error("We were not able to determine the module name.")

Expand Down Expand Up @@ -120,7 +121,7 @@ def normalize_modules(modules, skip_validation):
if detect_md_engine(engine_name) is None:
console.error(
"There is currently no support for '{}'. "
"Supported MD engines are: gromacs, namd.",
"Supported MD engines are: gromacs, namd, lammps.",
engine_name,
)

Expand Down
83 changes: 83 additions & 0 deletions mdbenchmark/mdengines/lammps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding:utf-8 -*-
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 fileencoding=utf-8
#
# MDBenchmark
# Copyright (c) 2017 Max Linke & Michael Gecht and contributors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Copyright (c) 2017 Max Linke & Michael Gecht and contributors
# Copyright (c) 2017-2018 The MDBenchmark development team and contributors

# (see the file AUTHORS for the full list of names)
#
# MDBenchmark is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# MDBenchmark is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MDBenchmark. If not, see <http://www.gnu.org/licenses/>.
import os
import re
from glob import glob
from shutil import copyfile

import mdsynthesis as mds
import numpy as np

from .. import console

NAME = "lammps"


def prepare_benchmark(name, *args, **kwargs):
sim = kwargs["sim"]

full_filename = name + ".in"
if name.endswith(".in"):
full_filename = name
name = name[:-3]

copyfile(full_filename, sim[full_filename].relpath)

return name


def analyze_lammps_file(fh):
""" Check whether the LAMMPS config file has any relative imports or variables
"""
lines = fh.readlines()

for line in lines:
# Continue if we do not need to do anything with the current line
if (
("parameters" not in line)
and ("coordinates" not in line)
and ("structure" not in line)
):
continue

path = line.split()[1]
if "$" in path:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all NAMD specific.

console.error("Variable Substitutions are not allowed in NAMD files!")
if ".." in path:
console.error("Relative file paths are not allowed in NAMD files!")
if "/" not in path or ("/" in path and not path.startswith("/")):
console.error("No absolute path detected in NAMD file!")


def check_input_file_exists(name):
"""Check and append the correct file extensions for the LAMMPS module."""
# Check whether the needed files are there.
fn = name
if fn.endswith(".in"):
fn = name[:-4]

infile = fn + ".in"
if not os.path.exists(infile):
console.error(
"File {} does not exist, but is needed for LAMMPS benchmarks.", infile
)


return True
8 changes: 8 additions & 0 deletions mdbenchmark/mdengines/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
FILES_TO_KEEP = {
"gromacs": [".*/bench\.job", ".*\.tpr", ".*\.mdp"],
"namd": [".*/bench\.job", ".*\.namd", ".*\.psf", ".*\.pdb"],
"lammps": [".*/bench\.job", ".*\.in"],
}

PARSE_ENGINE = {
Expand All @@ -48,6 +49,13 @@
"ncores_return": lambda line: int(line.split()[3]),
"analyze": "*out*",
},
"lammps": {
"performance": "Performance",
"performance_return": lambda line: 1 / float(line.split()[1]),
"ncores": "Loop",
"ncores_return": lambda line: int(line.split()[5]),
"analyze": "*log*",
}
}


Expand Down
2 changes: 2 additions & 0 deletions mdbenchmark/templates/cobra
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ module load {{ module }}
srun gmx_mpi mdrun -v -maxh {{ time / 60 }} -deffnm {{ name }}
{%- elif mdengine == "namd" %}
srun namd2 {{ name }}.namd
{%- elif mdengine == "lammps" %}
srun lmp_mpi -v f tmp.out -l my.log -sc none -i in.alloy
{%- endif %}
2 changes: 2 additions & 0 deletions mdbenchmark/templates/draco
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ module load {{ module }}
srun gmx_mpi mdrun -v -maxh {{ time / 60 }} -deffnm {{ name }}
{%- elif mdengine == "namd" %}
srun namd2 {{ name }}.namd
{%- elif mdengine == "lammps" %}
srun lmp_mpi -v f tmp.out -l my.log -sc none -i in.alloy
{%- endif %}
2 changes: 2 additions & 0 deletions mdbenchmark/templates/hydra
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ module load cuda
poe gmx_mpi mdrun -deffnm {{ name }} -maxh {{ time / 60 }}
{%- elif mdengine == "namd" %}
poe namd2 {{ name }}.namd
{%- elif mdengine == "lammps" %}
poe lmp_mpi -v f tmp.out -l my.log -sc none -i {{ name }}.in
{%- endif %}