Skip to content

Commit

Permalink
Fixed issue in nnp-checkf (non-periodic cases)
Browse files Browse the repository at this point in the history
Added tests and documentation
  • Loading branch information
singraber committed Apr 12, 2021
1 parent 12264df commit 7457aee
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 10,420 deletions.
3,040 changes: 0 additions & 3,040 deletions examples/nnp-checkf/Cu2S_PBE/input.data

This file was deleted.

282 changes: 0 additions & 282 deletions examples/nnp-checkf/Cu2S_PBE/input.nn

This file was deleted.

153 changes: 0 additions & 153 deletions examples/nnp-checkf/Cu2S_PBE/scaling.data

This file was deleted.

2,517 changes: 0 additions & 2,517 deletions examples/nnp-checkf/Cu2S_PBE/weights.016.data

This file was deleted.

2,367 changes: 0 additions & 2,367 deletions examples/nnp-checkf/Cu2S_PBE/weights.029.data

This file was deleted.

2,056 changes: 0 additions & 2,056 deletions examples/nnp-checkf/H2O_RPBE-D3/input.data

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/application/nnp-checkf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ int main(int argc, char* argv[])
delta);
if (myRank == 0)
{
string fileName = "forces.out";
string fileName = "checkf-forces.out";
dataset.log << strpr("Individual analytic/numeric forces will be "
"written to \"%s\"\n", fileName.c_str());
outFileForces.open(fileName.c_str());
Expand Down Expand Up @@ -113,9 +113,10 @@ int main(int argc, char* argv[])
appendLinesToFile(outFileForces,
createFileHeader(title, colSize, colName, colInfo));

fileName = "summary.out";
fileName = "checkf-summary.out";
dataset.log << strpr("Per-structure summary of analytic/numeric force "
"comparison will be written to \"%s\"\n",
"comparison will be \n"
"written to \"%s\"\n",
fileName.c_str());
outFileSummary.open(fileName.c_str());
// File header.
Expand Down
4 changes: 3 additions & 1 deletion src/doc/sphinx/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# import sys
# sys.path.insert(0, os.path.abspath('.'))

import sphinx_rtd_theme

# -- General configuration ------------------------------------------------

Expand All @@ -33,7 +34,8 @@
extensions = [
'breathe',
# 'exhale',
'sphinx.ext.mathjax'
'sphinx.ext.mathjax',
'sphinx_rtd_theme'
]

# Setup the breathe extension
Expand Down
1 change: 1 addition & 0 deletions src/doc/sphinx/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ list of keywords is provided :ref:`here <keywords>`.

tools/libnnp
tools/nnp-atomenv
tools/nnp-checkf
tools/nnp-convert
tools/nnp-norm
tools/nnp-predict
Expand Down
79 changes: 79 additions & 0 deletions src/doc/sphinx/source/tools/nnp-checkf.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
.. _nnp-checkf:

nnp-checkf
==========

This tool is useful for debugging as it computes numeric forces via the
symmetric difference quotient (central difference) and compares it to the
analytic forces obtained directly from n2p2's prediction. Parallelization via
MPI is supported and it can process multiple configurations in the input file.

Requirements:
-------------

The HDNNP setup, symmetry function scaling data and weight parameters are
required in the usual files. The data file ``input.data`` may contain multiple
configurations.

* ``input.data``
* ``input.nn``
* ``scaling.data``
* ``weights.???.data``

Usage:
------

.. code-block:: none
mpirun -np <np> nnp-checkf <<delta>>
where

.. code-block:: none
<np> ........ Number of MPI processes to use.
<<nbins>> ... (optional) Displacement for central difference (default: 1.0e-4).
The ``<<delta>>`` parameter determines the position displacement of atoms used
for the central difference approximation of the forces. If no value is provided
the default is :math:`\delta = 10^{-4}`.

Sample screen output:
---------------------

.. code-block:: none
*** ANALYTIC/NUMERIC FORCES CHECK *********************************************
Delta for symmetric difference quotient: 1.000E-04
Individual analytic/numeric forces will be written to "checkf-forces.out"
Per-structure summary of analytic/numeric force comparison will be
written to "checkf-summary.out"
Found 3 configurations in data file: input.data.
Starting loop over 3 configurations...
numForces meanAbsError maxAbsError verdict
-------------------------------------------------------------------
Configuration 1: 144 7.168E-10 2.984E-09 OK.
Configuration 2: 144 8.215E-10 3.212E-09 OK.
Configuration 3: 144 7.254E-10 2.459E-09 OK.
*******************************************************************************
File output:
------------

* ``checkf-forces.out``: Comparison of analytic/numeric values, each force one
line.

* ``checkf-summary.out``: Per-structure accumulated comparison (same as screen
output).

Examples:
---------

* Run on 4 cores and override default :math:`\delta` value:

.. code-block:: none
mpirun -np 4 nnp-checkf 1.0E-3
2 changes: 1 addition & 1 deletion src/libnnptrain/Dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ size_t Dataset::prepareNumericForces(Structure& original, double delta)
s.comment = strpr("%zu %zu %zu %d", count, iAtom, ixyz, sign);
// Modify atom position.
s.atoms.at(iAtom).r[ixyz] += sign * delta;
s.remap(s.atoms.at(iAtom));
if (s.isPeriodic) s.remap(s.atoms.at(iAtom));
}
count++;
}
Expand Down
29 changes: 29 additions & 0 deletions test/cpp/Example_nnp_checkf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef EXAMPLE_NNP_CHECKF_H
#define EXAMPLE_NNP_CHECKF_H

#include "Example_nnp.h"
#include "BoostDataContainer.h"

struct Example_nnp_checkf : public Example_nnp
{
Example_nnp_checkf(std::string name)
: Example_nnp("nnp-checkf", name) {};
};

template<>
void BoostDataContainer<Example_nnp_checkf>::setup()
{
Example_nnp_checkf* e = nullptr;

examples.push_back(Example_nnp_checkf("H2O_RPBE-D3"));
e = &(examples.back());
e->args = "";

examples.push_back(Example_nnp_checkf("LJ"));
e = &(examples.back());
e->args = "";

return;
}

#endif
23 changes: 23 additions & 0 deletions test/cpp/test_nnp-checkf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE nnp-checkf
#include "Example_nnp_checkf.h"
#include "nnp_test.h"

#include <limits> // std::numeric_limits

using namespace std;

double const accuracy = 10.0 * numeric_limits<double>::epsilon();

BoostDataContainer<Example_nnp_checkf> container;

NNP_TOOL_TEST_CASE()

void nnpToolTestBody(Example_nnp_checkf const /*example*/)
{
BOOST_REQUIRE(bfs::exists("nnp-checkf.log.0000"));
BOOST_REQUIRE(bfs::exists("checkf-forces.out"));
BOOST_REQUIRE(bfs::exists("checkf-summary.out"));

return;
}

0 comments on commit 7457aee

Please sign in to comment.