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

Closes #1536: implement periodic boundary conditions #1853

Merged
merged 19 commits into from Jan 25, 2020

Conversation

bbucior
Copy link
Contributor

@bbucior bbucior commented Jun 9, 2018

This PR partially implements periodic boundary conditions in Open Babel by applying the minimum image convention and using OBUnitCell data. Some formats or existing code may not be expecting this behavior, so it is currently hidden behind an OB_PERIODIC_MOL flag in OBMol. See also openbabel/enhancement-proposals#6 for more discussion. Currently this PR is more of a minimum viable product, but over the summer I'm planning to submit additional PR's after combing through more of the codebase.

This PR also adds an option to write bonding information to CIF output, including notation for bonds across periodic boundaries.

Before the code can be merged, there's a handful of details to take care of:

  1. There are some merge conflicts (and we should be careful that any changes are compatible with PR#1823). What's the quickest/cleanest way to address these?
  2. Const correctness is tricky: I couldn't keep the const keyword on OBBond::GetLength() without making a lot of other changes to OBMol::HasFlag and some related methods.
  3. What is best practice for the argument of OBGenericData->Clone(NULL)? Is it NULL, the OBMol, or something context-dependent?
  4. Any other comments or cleanup would also be appreciated. Thanks!

Special thanks to Giovanni Garberoglio for helpful discussion and his code in http://software-lisc.fbk.eu/obgmx/. I tried to combine the best parts of both of our PBC implementations in this PR.

Used `git apply` to apply relevant code for periodic boundary
conditions from an ongoing research project.  More cleanup necessary
before upstream integration.
Adopt MinimumImageFractional and MinimumImageCartesian notation from
Giovanni Garberoglio's implementation to replace the PBCDifference
methods.
Avoid cluttering the Open Babel API, now that earlier research code
has been refactored.
My previous iteration of periodic boundary conditions in OBMol added
an extra copy of OBUnitCell* to the OBMol object, which was
undesirable because (1) it clutters the API, and (2) leads to
consistency problems.  Now, there is only one copy of OBUnitCell*
within the molecule's data.
These cases cover periodic boundaries and bond output for CIFs
include/openbabel/mol.h Outdated Show resolved Hide resolved
include/openbabel/mol.h Outdated Show resolved Hide resolved
@ghutchis
Copy link
Member

Overall, this looks good. Obviously having a periodic UFF would be great.

  1. The only way to handle merge conflicts is manually. So take mmcifformat.cpp from master and work in any remaining changes, etc.

  2. OBBond::GetLength really needs to be const

  3. The Clone command is called when copying generic data from one molecule to another. If you're keeping track of atom pointers, etc. you'll need a context-dependent version..

Periodic boundary code is based on an old version of Open Babel, so I
attempted to manually resolve the merge conflicts identified by Github
(and ran diff against the current master and periodic-boundaries
branches to verify).
Updated mmcifformat.cpp, mol.cpp, and CMakeLists.txt to resolve
remaining merge conflicts.
@bbucior
Copy link
Contributor Author

bbucior commented Jun 15, 2018

Thank you for the feedback.

  1. Conflicts resolved
  2. One challenge I ran into was that some of the existing code wasn't declared as const. I can restore const to OBBond::GetLength if some of the other methods are declared as const. Before making a commit, does this example change look reasonable, or are there other concerns about API compatibility, etc?
  3. I think I understand. I don't recall anything seeing anything context-specific in OBUnitCell, but keeping track of the molecule anyway probably wouldn't hurt. The line I was looking at is newmol.SetData(parent_uc->Clone(NULL)); (in OBMol::CopySubstructure), so I think the relevant OBMol would be &newmol.

Making sure the UFF code is PBC-compatible sounds like a great feature. I will work on that after porting some more PBC features from my research code (such as different formats than CIF) to another PR.

@ghutchis
Copy link
Member

Okay, this looks okay if you can fix the new set of conflicts. Thanks for your patience - I think this will be really helpful. (I have some ideas about packing molecules using code like this and distance geometry / fragment placement.)

Resolved remaining merge conflicts in mol.h and mol.cpp
Restored const to OBBond::GetLength.  Avoided changes to existing API
by dereferencing the `this` pointer as done by similar methods in the
code.
@bbucior
Copy link
Contributor Author

bbucior commented Jul 22, 2018

Great! I resolved the merge conflicts and made sure not to change any of the const declarations in the existing API. Thanks for your help--I think this is good to go.

@bbucior
Copy link
Contributor Author

bbucior commented Sep 5, 2018

@ghutchis I'm going to try and get the periodic UFF code ready as a separate PR next week. Do you think you'll have time to review this PR before then?

The coordinates in the atom and bond fields did not match because wrapping had been applied inconsistently.  This discrepancy confused a visualization program when parsing the bond symmetry flags.
@bbucior
Copy link
Contributor Author

bbucior commented Mar 12, 2019

I cleaned up the new merge conflicts and patched a bug I had found while using the code in my research. Those are all the changes I had planned for now, unless there are any requests.

@ghutchis
Copy link
Member

I'm going to commit this to master - hopefully the merge was successful. (We'll find out once it re-runs tests.)

@bbucior
Copy link
Contributor Author

bbucior commented Jan 25, 2020

The build is passing again now that merge conflicts have been resolved and the branch has been updated in light of #1951 and #1958.

@ghutchis
Copy link
Member

Looks good - I'm going to merge this. Many thanks!

@ghutchis ghutchis merged commit 3d6384b into openbabel:master Jan 25, 2020
@baoilleach
Copy link
Member

Just looking at this now in the context of the 3.0.1 release. I see a couple of TODOs in there based on memory allocation and pointers. Do you need/want feedback on these?

@bbucior
Copy link
Contributor Author

bbucior commented May 9, 2020

Hi @baoilleach hope you are doing well. Thanks for your interest and offer to help. Is there any section of code in particular that would be good to clean up? From what I remember, most of the remaining TODOs were either in SetLength (and related methods) or file formatters that still calculated geometry from raw vector3's instead of atom/bond distances.

I'd be happy to take another look and do some more cleanup, though making Open Babel fully PBC-aware wouldn't be something I could commit to right now. I'm not currently dogfooding the code for research, and implementing PBC the right way might require some larger architectural discussions to see if there's a way to more generically handle coordinates (perhaps an OBCoord class?).

@baoilleach
Copy link
Member

Currently tied up with the release. Let's talk later...

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.

None yet

3 participants