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

add biased voronoi cells feature #593

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
344d6de
add container_periodic_poly function
yuanzhou0827 Mar 6, 2020
6d85975
make header files consistently
yuanzhou0827 Mar 6, 2020
5969de0
revert to the original for testing
yuanzhou0827 Mar 6, 2020
618d3e1
only polydisperse
yuanzhou0827 Mar 7, 2020
40e899c
unsigned is not applied double or float.
yuanzhou0827 Mar 7, 2020
ef32aef
reduce the if_else loops
yuanzhou0827 Mar 7, 2020
e80cea0
default values can only be set in header file, and give the container…
yuanzhou0827 Mar 7, 2020
f5a8687
the way for a point to call a function is ->
yuanzhou0827 Mar 7, 2020
133ff92
use container_periodic_poly only
yuanzhou0827 Mar 8, 2020
fb13e75
add container_periodic_poly function
yuanzhou0827 Mar 6, 2020
c78a6c1
make header files consistently
yuanzhou0827 Mar 6, 2020
71feecd
revert to the original for testing
yuanzhou0827 Mar 6, 2020
9228ab4
only polydisperse
yuanzhou0827 Mar 7, 2020
a4b1323
unsigned is not applied double or float.
yuanzhou0827 Mar 7, 2020
db1a753
reduce the if_else loops
yuanzhou0827 Mar 7, 2020
3c9523b
default values can only be set in header file, and give the container…
yuanzhou0827 Mar 7, 2020
785f4e6
the way for a point to call a function is ->
yuanzhou0827 Mar 7, 2020
689665b
use container_periodic_poly only
yuanzhou0827 Mar 8, 2020
370158a
Intermediate commit with fixes
yuanzhou0827 Mar 12, 2020
98009ba
Merge branch 'bias_vor' of https://github.com/glotzerlab/freud into b…
yuanzhou0827 Mar 16, 2020
ab3f73f
resolve the variable type problem
yuanzhou0827 Mar 18, 2020
0ce8d91
wrap long lines
yuanzhou0827 Mar 18, 2020
cd65474
variable type
yuanzhou0827 Mar 18, 2020
f17ab2a
variable type correction
yuanzhou0827 Mar 19, 2020
d1de530
finalize the format
yuanzhou0827 Mar 19, 2020
56458a8
flake8 formatted
yuanzhou0827 Mar 19, 2020
376ff30
docstring added
yuanzhou0827 Mar 19, 2020
030d95f
Merge remote-tracking branch 'origin/master' into bias_vor
bdice Nov 6, 2020
e165531
Apply suggestions from code review
bdice Nov 6, 2020
75a6551
Apply suggestions from code review
bdice Nov 6, 2020
2fb9d47
Use nullptr.
bdice Nov 6, 2020
affde15
Update comments and clang-format.
bdice Nov 6, 2020
c1d032a
Merge branch 'master' into bias_vor
bdice Nov 21, 2021
ddf0e9e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2021
d4e5e6c
Merge branch 'master' into bias_vor
yuanzhou0827 Jan 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions cpp/locality/Voronoi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace freud { namespace locality {

// Voronoi calculations should be kept in double precision.
void Voronoi::compute(const freud::locality::NeighborQuery* nq)
void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* radii)
{
auto box = nq->getBox();
auto n_points = nq->getNPoints();
Expand All @@ -40,20 +40,23 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq)
// having to create a pre_container. This saves time because the
// pre_container cannot be used to set up container_periodic (only
// non-periodic containers are compatible).
// Also, we enable the weighted voronoi diagram if the sizes of different
// points are provided; otherwise, the default is unbiased voronoi shapes
// calculations.
float block_scale = std::pow(n_points / (voro::optimal_particles * box.getVolume()), 1.0 / 3.0);
int voro_blocks_x = int(box.getLx() * block_scale + 1);
int voro_blocks_y = int(box.getLy() * block_scale + 1);
int voro_blocks_z = int(box.getLz() * block_scale + 1);

voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y,
boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z,
voro_blocks_x, voro_blocks_y, voro_blocks_z, 3);

voro::container_periodic_poly container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y,
boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z,
voro_blocks_x, voro_blocks_y, voro_blocks_z, 3);
for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++)
{
vec3<double> query_point((*nq)[query_point_id]);
yuanzhou0827 marked this conversation as resolved.
Show resolved Hide resolved
container.put(query_point_id, query_point.x, query_point.y, query_point.z);
}
double radius = (radii != NULL) ? radii[query_point_id] : 0.0;
yuanzhou0827 marked this conversation as resolved.
Show resolved Hide resolved
container.put(query_point_id, query_point.x, query_point.y, query_point.z, radius);
}

voro::voronoicell_neighbor cell;
voro::c_loop_all_periodic voronoi_loop(container);
Expand Down
2 changes: 1 addition & 1 deletion cpp/locality/Voronoi.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Voronoi
// default constructor
Voronoi() : m_neighbor_list(std::make_shared<NeighborList>()) {}

void compute(const freud::locality::NeighborQuery* nq);
void compute(const freud::locality::NeighborQuery* nq, const double* radii = NULL);

std::shared_ptr<NeighborList> getNeighborList() const
{
Expand Down
3 changes: 2 additions & 1 deletion freud/_locality.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ cdef extern from "PeriodicBuffer.h" namespace "freud::locality":
cdef extern from "Voronoi.h" namespace "freud::locality":
cdef cppclass Voronoi:
Voronoi()
void compute(const NeighborQuery*) nogil except +
void compute(const NeighborQuery*,
const double*) nogil except +
vector[vector[vec3[double]]] getPolytopes() const
const freud.util.ManagedArray[double] &getVolumes() const
shared_ptr[NeighborList] getNeighborList() const
15 changes: 13 additions & 2 deletions freud/locality.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1120,17 +1120,28 @@ cdef class Voronoi(_Compute):
def __dealloc__(self):
del self.thisptr

def compute(self, system):
def compute(self, system, radii=None):
R"""Compute Voronoi diagram.

Copy link
Member

Choose a reason for hiding this comment

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

We need to add a longer description of Voronoi diagrams and how this feature works. I think it might go best in the class docstring. It should include external links, formulas/equations, and descriptions of why someone would want to use this feature. It's important to include the several names for this feature so that it can be found via Google / documentation search. Please verify what type of weighted Voronoi diagram we are computing (additively weighted, multiplicatively weighted, or something else?), and cite whatever references you can find. You may need to refer to the voro++ documentation.

Args:
system:
Any object that is a valid argument to
:class:`freud.locality.NeighborQuery.from_system`.
radii:
A list of :class:`numpy.ndarray` defining radii of points in
the system. (Default value = :code:`None`, meaning unbiased
Voronoi diagram.)
bdice marked this conversation as resolved.
Show resolved Hide resolved
"""
cdef NeighborQuery nq = NeighborQuery.from_system(system)
self.thisptr.compute(nq.get_ptr())
self._box = nq.box
if radii is None:
radii = np.zeros(len(nq.points), dtype=np.float64)
radii = freud.util._convert_array(
radii,
shape=(len(nq.points),),
dtype=np.float64)
cdef double[::1] l_radii = radii
self.thisptr.compute(nq.get_ptr(), &l_radii[0])
bdice marked this conversation as resolved.
Show resolved Hide resolved
return self

@_Compute._computed_property
Expand Down