Dear Axel,
Thank you so much for such a prompt response and implementation of the feature! I can’t believe I have not thought of just building an inverse map myself. I have successfully ran your example with in.peptide file, however, for some reason when I try this on my system, the map does not seem to get build. I assume that is the case as I am getting a “-1” returned as a result of any lmp.map_atom(tag) call. I just can’t figure out what triggers the creation of a map (if that is even the issue). Here are all the files that I am trying this with.
Also, here is the python code just to have it in the question:
from lammps import lammps
lmp = lammps(cmdargs = ["-log", "none", "-screen", "none"])
lmp.command("units real")
lmp.command("atom_style charge")
lmp.command("read_data glass_SiO.structure")
lmp.command("include pot_SiO.FF")
lmp.command("neighbor 2.0 bin")
lmp.command("run 0")
tags = lmp.extract_atom("id")
sometags = [1, 10, 25, 100]
for mytag in sometags:
myidx = lmp.map_atom(mytag)
print("tag = %d idx = %d check = %d" % (mytag, myidx, tags[myidx]))
lmp.close()
Output:
tag = 1 idx = -1 check = 0
tag = 10 idx = -1 check = 0
tag = 25 idx = -1 check = 0
tag = 100 idx = -1 check = 0
EDIT:
I have also noticed that looping over the lammps.extract_atom(“id”) object throws the following segmentation fault error at the end:
*** Process received signal ***
Signal: Segmentation fault (11)
Signal code: Address not mapped (1)
Failing at address: 0x5e068f766000
The same error (I understand it’s very generic) is present when trying to convert this “tags” object to a list via the list() method. A slightly different error appears when trying to convert it to a numpy array:
File "working_venv/lib/python3.10/site-packages/numpy/core/_internal.py", line 654, in _dtype_from_pep3118
dtype, align = __dtype_from_pep3118(stream, is_subdtype=False)
File "working_venv/lib/python3.10/site-packages/numpy/core/_internal.py", line 727, in __dtype_from_pep3118
raise NotImplementedError(
NotImplementedError: Unrepresentable PEP 3118 data type '&' (pointers)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "peptide/test.py", line 8, in <module>
tags = np.array(lmp.extract_atom('id'))
ValueError: '&<i' is not a valid PEP 3118 buffer format string
(
I’m guessing it has something to do with an incorrect pointer assignment at the end of iteration, but this is only a guess.
Also, I am unsure whether it is appropriate to keep adding questions to this thread, so if you believe it is better for me to start the new one, please let me know.
Thank you again,
Vasilii