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

A draft for read and write bond type for lammps data #478

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

Roy-Kid
Copy link

@Roy-Kid Roy-Kid commented Jun 10, 2023

Dear @Luthaf and other developers,

According to the previous discussion #476 , I write an untested draft that read and write bond type from lammps data file. In this PR, I want to read and write bond/angle/dihedral data from lammps data and trajectory.

Since issue #462 is planning to support symbolic atom type, I choose std::string as the representation for bond type.

In the following code, I completely complied with the storage method of BondOrder. But here I want to initiate a discussion about whether to use bond type or even bond order as a member attribute of Bond, like type in Atom. I think the benefits are as follows: The form is tidier, and the bond information can be obtained directly by iterating topology.bonds

I hope you can review my code in your free time so that I can complete these features in the future~

Thanks a lot!

Copy link
Member

@Luthaf Luthaf left a comment

Choose a reason for hiding this comment

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

Sorry for the very long delay for the review. This looks pretty good overall!

My main concern is about the handling of bond types in the LAMMPS code. It looks like currently the code will create a set containing all bonds, where we would like to only have one entry per bond type (which should be a much smaller number).

I think the code should try to look for bond types in the topology, and if it can not find one, fallback to the old bond type generation.


The new bond type parameter to add_bond should also be added to the C API, to make it accessible from Python/Rust/Julia/...

include/chemfiles/Connectivity.hpp Outdated Show resolved Hide resolved
include/chemfiles/Topology.hpp Outdated Show resolved Hide resolved
include/chemfiles/Topology.hpp Outdated Show resolved Hide resolved
src/formats/LAMMPSData.cpp Outdated Show resolved Hide resolved
src/formats/LAMMPSData.cpp Outdated Show resolved Hide resolved
src/Topology.cpp Outdated Show resolved Hide resolved
/// @param atom_j the index of the second atom in the bond
/// @throws OutOfBounds if `atom_i` or `atom_j` are greater than `size()`
/// @throws Error if no bond between `atom_i` and `atom_j` exists.
std::string bond_type(size_t atom_i, size_t atom_j) const;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
std::string bond_type(size_t atom_i, size_t atom_j) const;
const std::string& bond_type(size_t atom_i, size_t atom_j) const;

this should return a const reference instead of a copy

src/formats/LAMMPSData.cpp Outdated Show resolved Hide resolved
include/chemfiles/formats/LAMMPSData.hpp Outdated Show resolved Hide resolved
Roy-Kid and others added 2 commits July 12, 2023 00:01
Co-authored-by: Guillaume Fraux <luthaf@luthaf.fr>
Co-authored-by: Guillaume Fraux <luthaf@luthaf.fr>
Roy-Kid

This comment was marked as off-topic.

Roy-Kid and others added 8 commits July 12, 2023 00:13
Co-authored-by: Guillaume Fraux <luthaf@luthaf.fr>
Co-authored-by: Guillaume Fraux <luthaf@luthaf.fr>
Co-authored-by: Guillaume Fraux <luthaf@luthaf.fr>
Co-authored-by: Guillaume Fraux <luthaf@luthaf.fr>
Co-authored-by: Guillaume Fraux <luthaf@luthaf.fr>
@Roy-Kid
Copy link
Author

Roy-Kid commented Jul 13, 2023

@Luthaf Hi, sorry for bothering you.
I re-wrote the code according to your suggestion. Now if it not find a custom bond type, it will degrade to integer bond type.
However, the custom bond type to integer bond type is one-to-one mapping, but the add_bond API is per-bond type mapping. For example, if 1-2 and 1-3 both bond type 1, after I do add_bond(1, 2, order, "typeA") and add_bond(1, 3, order, "typeB"), the bond type in lammpsdata is both typeB. The later bond_type will override the former one.
Should we use the rule: check if user defines a per-bond type, for example, add_bond(1, 2, order, "typeA"). If so, use "typeA" instead of the original type 1, if not, degrade it to type 1;

@Luthaf
Copy link
Member

Luthaf commented Aug 17, 2023

However, the custom bond type to integer bond type is one-to-one mapping, but the add_bond API is per-bond type mapping. For example, if 1-2 and 1-3 both bond type 1, after I do add_bond(1, 2, order, "typeA") and add_bond(1, 3, order, "typeB"), the bond type in lammpsdata is both typeB.

I'm not sure I understand here. add_bond is the chemfiles function, right? In this case, why would add_bond(1, 2, order, "typeA") followed by add_bond(1, 3, order, "typeB") result in both bonds having typeB? I would expect that this results in two bonds (1-2 with typeA; and 1-3 with typeB). I'll re-read through the code as well to try to understand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants