Error when trying to compile with new potentials

I want to add two potentials for the YAG system. To do this, I’m trying to put some .cpp .h files in src and compile (tried make and cmake). Errors appear:

[ 87%] Building CXX object CMakeFiles/lammps.dir/home/artem/lammps/src/pair_mbmh.cpp.o

/home/artem/lammps/src/pair_mbmh.cpp: In member function ‘virtual void LAMMPS_NS::PairMBMH::init_style()’:

/home/artem/lammps/src/pair_mbmh.cpp:269:39: error: ‘int LAMMPS_NS::NeighRequest::half’ is protected within this context

  269 |         neighbor->requests[irequest]->half=0;

      |                                       ^~~~

In file included from /home/artem/lammps/src/pair_mbmh.cpp:22:

/home/artem/lammps/src/neigh_request.h:54:7: note: declared protected here

   54 |   int half;    // half neigh list (set by default)

      |       ^~~~

/home/artem/lammps/src/pair_mbmh.cpp:270:39: error: ‘int LAMMPS_NS::NeighRequest::full’ is protected within this context

  270 |         neighbor->requests[irequest]->full=1;

      |                                       ^~~~

In file included from /home/artem/lammps/src/pair_mbmh.cpp:22:

/home/artem/lammps/src/neigh_request.h:55:7: note: declared protected here

   55 |   int full;    // full neigh list

      |       ^~~~

/home/artem/lammps/src/pair_mbmh.cpp: In member function ‘void LAMMPS_NS::PairMBMH::read_file(char*)’:

/home/artem/lammps/src/pair_mbmh.cpp:324:22: error: ‘class LAMMPS_NS::Atom’ has no member named ‘count_words’

  324 |         nwords=atom->count_words(line);

      |                      ^~~~~~~~~~~

/home/artem/lammps/src/pair_mbmh.cpp:342:30: error: ‘class LAMMPS_NS::Atom’ has no member named ‘count_words’

  342 |                 nwords=atom->count_words(line);

      |                              ^~~~~~~~~~~

gmake[2]: *** [CMakeFiles/lammps.dir/build.make:5018: CMakeFiles/lammps.dir/home/artem/lammps/src/pair_mbmh.cpp.o] Error 1

gmake[1]: *** [CMakeFiles/Makefile2:171: CMakeFiles/lammps.dir/all] Error 2

gmake: *** [Makefile:136: all] Error 2

What could be the problem? Everything worked for my supervisor, but I have lost contact with him now. I tried compiling a clean version and recompiling a ready version with new files. The error is the same.

This code was written for an old version of LAMMPS. The compilation error is a manifestation of the risks of having custom source code outside the LAMMPS distribution: when there a modifications to the internal programming interfaces, the external code will no longer compile.

Thus you either need to compile this pair style with a compatible, older version of LAMMPS (the one that it was written for) - which is not recommended - or it needs to be ported to the current LAMMPS version. Some porting hints are collected here: 4.10. Notes for updating code written for older LAMMPS versions — LAMMPS documentation
Or you can look at the detailed discussion on implementing new pair styles: 4.8.1. Writing new pair styles — LAMMPS documentation

Oh, that makes sense, thanks. I guess just upgrading to an older version will be enough to solve this little task, but just which one…? I didn’t find any version hints when I opened the .cpp file, I guess it’s not so trivial to define a specific version? Is it possible to solve it without going through all the versions? :grimacing:

This is not recommended. You are missing out on all the bug fixes and new features in LAMMPS.
The issue you are seeing should be easily correctable with the information in the pages in the manual I was pointing out.

1 Like

Okay, I’ll give it a try.

I fixed everything except for this error:

/home/artem/lammps23/src/pair_mbmh.cpp:323:22: error: ‘class LAMMPS_NS::Atom’ has no member named ‘count_words’

  323 |         nwords=atom->count_words(line);

      |                      ^~~~~~~~~~~

/home/artem/lammps23/src/pair_mbmh.cpp:341:30: error: ‘class LAMMPS_NS::Atom’ has no member named ‘count_words’

  341 |                 nwords=atom->count_words(line);

      |                              ^~~~~~~~~~~





tbh, I’m not familiar with it, I don’t fully understand why these lines are needed and what to fix here.

This seems to be a part of a parser for reading a file with potential parameters.

Please check out: 4.15. Utility functions — LAMMPS documentation

1 Like

Please note that “utils::count_words()” does not remove comments starting with ‘#’.
If that is needed, you need to use:

    nwords = utils::count_words(utils::trim_comment(line));

I will add a paragraph about this function to the documentation. It must have slipped through the cracks so far, since this function is not needed when updating the potential file parser to use the tokenizer and file reader classes: 4.9. Notes for developers and code maintainers — LAMMPS documentation

1 Like

One general note. Is this code available for the general public somewhere?
If not, consider contributing it for either the LAMMPS plugins repository (no review, no documentation, no testing, no guarantees, assistance with further modernizing the code and keeping it usable with current LAMMPS versions) or for general distribution to the LAMMPS repository (requires documentation, will be subject to testing, and code review).

As frequent forum contributor @srtee is often telling people, using unpublished software or even unpublished non-trivial input decks for scientific research makes it impossible to reproduce results and thus taints the value of any such results. There is a website discussing the FAIR principles.

1 Like