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

Periodic boundary condition #71

Merged
merged 14 commits into from
Jul 12, 2024
Merged

Conversation

yaoyi92
Copy link
Contributor

@yaoyi92 yaoyi92 commented Jul 11, 2024

Implement the periodic boundary condition.

  1. The distances among atoms are calculated with pbc in consideration, for both f values and their gradient using minimum image convention.
  2. The cell lists are initialized in the space of pbc box and the interacting box cell lists are calculated with pbc in consideration.
  3. An example of a pbc water box is added in the testing folder.
  4. The input keyword is pbc cellx celly cellz

@lmiq
Copy link
Member

lmiq commented Jul 11, 2024

Thanks. This is very interesting. One thing that prevented me from implementing that was what to do with the relation of other constraints with the coordinates. For example, if the user sets over plane 0. 0. 0. 1., how will this relate to the periodic boundary conditions?

In your implementation, can we guarantee that the atoms are always in the 0 0 0 sidemax sidemax sidemax box, such that over plane 0. 0. sidemax/2 1. would make sense?

(I'll take a look carefully now, but I think we can discuss a little bit these details at the same time, as we will need to update the documentation)

@lmiq
Copy link
Member

lmiq commented Jul 11, 2024

In other words, for PBCs to support most generally the constraints the Packmol supports, we need to wrap the coordinates with some criterium before computing the constraints. I think the most sensible criterium would be to wrap them to the first all-positive box, that is, to the box with coordinates 0.0 0.0 0.0 sidemax sidemax sidemax.

With that, we should remove the obligatory definition of constraints for the types of molecules. For example, in the example you provided:

tolerance 2.0
filetype pdb
output water_box.pdb
pbc 31. 31. 31.

structure water.pdb
  number 1000
  inside box 0. 0. 0. 31. 31. 31.
end structure

The inside box constraint is not necessary. And it also defeats the purpose of the pbc, as the molecules will restricted by the boundary of the box. Ideally this example should be:

tolerance 2.0
filetype pdb
output water_box.pdb
pbc 31. 31. 31.

structure water.pdb
  number 1000
end structure

One alternative could be to define the PBCs with box constraints, like:

pbc 0.0 0.0 0.0 31.0 31.0 31.0

which would mean that atoms will be always wrapped into the box with those maximum and minimum coordinates, and the box lengths are 31.0, in the example, in all directions. Providing the pbc with only 3 coordinates could be a shortcut notation to using minimum coordinates 0.0 0.0 0.0.

@yaoyi92
Copy link
Contributor Author

yaoyi92 commented Jul 11, 2024

Yes, I totally agree that constraints and periodic boundary conditions are not compatible mathematically, given that non of these constraints are periodic functions.

However, the constraints can still be helpful. That's why I hope to keep the approach I take. In the implementation, I didn't wrap the atoms. The atoms still hold their cartesian coordinates; and, the constraints are still there applied based on these cartesian coordinates. Only when calculating the atom pair interaction for the f value, I used the periodic minimum image convention definition of their distance/displacement. I hope to keep it this way since it gave me the flexibility to combine the use of constraints and periodic boundary condition. That's also why I hope to keep the inside box constraint in the example. It allows me to specify where the molecules packed.

As an example, this input can help generate a box of water-air interface like the one in this paper https://doi.org/10.1021/jp1067022

tolerance 2.0
filetype pdb
output water_box.pdb
pbc 100. 31. 31.

structure water.pdb
  number 1000
  inside box 30. 0. 0. 61. 31. 31.
end structure

@lmiq
Copy link
Member

lmiq commented Jul 12, 2024

So I think what we have to do, which would be fine, would be to automatically add a constraint to every atom which consisted in the limits of the PBC plus half of the tolerance. Meaning, if one sets:

tolerance 2.0
pbc 30.0 30.0 30.0
structure water.pdb
    number 1000
end

This should be equivalent to

pbc 30.0 30.0 30.0
structure water.pdb
    inside box -1.0 -1.0 -1.0 31.0 31.0 31.0
    number 1000
end

and the same inside box constraint is added to all non-fixed structures of the system.

Do you think you can try to implement that? I'm really out of time now.

@yaoyi92
Copy link
Contributor Author

yaoyi92 commented Jul 12, 2024

I believe these commits complete the request of adding an implicit constraint for all the atoms.

@lmiq
Copy link
Member

lmiq commented Jul 12, 2024

For being reassured about the implications of this and future updates of the package, I have implemented a new testing framework.

It is merged into master. Could you please add your tests within the same framework. Should be easy:

  • Add the input file to testing/input_files and use structure ./structure_files/water.pdb as for the structure file definition (this is just for organizing the tests).
  • Set the name of the output to output.pdb (not really required, but minimizes the chances of committing testing output files).
  • Add a line associated to the test in ./testing/test.sh, in the juila call. Currently we have:
    julia runtests.jl ./input_files/water_box.inp \
                    ./input_files/ieee_signaling.inp \
                    ./input_files/mixture.inp \
                    ./input_files/spherical.inp \
                    ./input_files/bilayer.inp \
                    ./input_files/solvprotein.inp
    

The tests run packmol and then check for the minimum distance obtained taking into consideration the periodic boundary conditions, if they were defined. With that, we can test more exhaustively the approach taken here.

@yaoyi92 yaoyi92 force-pushed the periodic_boundary_condition branch from d72eb0d to 6836021 Compare July 12, 2024 14:11
@yaoyi92
Copy link
Contributor Author

yaoyi92 commented Jul 12, 2024

Not very familiar with Julia.
But, I got this error during the test.
LoadError: TypeError: in keyword argument unitcell, expected Union{Nothing, AbstractVecOrMat}, got a value of type Tuple{SubString{String}, SubString{String}, SubString{String}
It looks like I would need to type cast Tuple{SubString{String}, SubString{String}, SubString{String} into AbstractVecOrMat in this line.
keyword == "pbc" && (unitcell = (values[1], values[2], values[3]))

Do you know how to do that?

@lmiq
Copy link
Member

lmiq commented Jul 12, 2024

fixed, I think (I didn't know that I could directly modify your code here)

@yaoyi92
Copy link
Contributor Author

yaoyi92 commented Jul 12, 2024

Thanks!
Now, for me, it passed the successful tests but failed the failed test.

# bash test.sh 
  Activating project at `~/packmol/packmol_yy/testing`
Error: could not find FORCED in packmol.log

@yaoyi92
Copy link
Contributor Author

yaoyi92 commented Jul 12, 2024

I saw the same error in the master branch.

@lmiq
Copy link
Member

lmiq commented Jul 12, 2024

I saw the same error in the master branch.

that's strange, it is working here and on CI.

Let's focus on your new test first, than I check that.

@lmiq lmiq merged commit e0a8029 into m3g:master Jul 12, 2024
8 checks passed
@lmiq
Copy link
Member

lmiq commented Jul 12, 2024

Thanks very much for the contribution. I'll make some tests and document and then release it.

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