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

OffLattice support #453

Merged
merged 60 commits into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
abb498b
:fire: Remove alias functions used for Cython
0ncorhynchus Sep 19, 2019
3e37965
:construction: Add python apis for offlattice
0ncorhynchus Sep 19, 2019
15148bb
:white_check_mark: Add a test for offlattice
0ncorhynchus Sep 19, 2019
91757f5
:boom: Add SpatiocyteWorld.add_offlattice()
0ncorhynchus Oct 11, 2019
1368c18
:sparkles: Add a class for generating OffLatticeSpace
0ncorhynchus Oct 24, 2019
cd8002a
:sparkles: Add an argument to add_offlattice()
0ncorhynchus Oct 31, 2019
8ae7e29
:recycle: Refactor remove_voxel()
0ncorhynchus Oct 31, 2019
4b5f6fe
Merge pull request #431 from 0ncorhynchus/offlattice
0ncorhynchus Dec 12, 2019
c60c004
:recycle: Remove some functions from VoxelSpaceBase
0ncorhynchus Nov 7, 2019
33fd82a
:fire: Remove other functions from VoxelSpaceBase
0ncorhynchus Nov 7, 2019
1694ae7
:fire: Remove VoxelSpaceBase::particle_at()
0ncorhynchus Nov 7, 2019
fc63aa3
:recycle: Impl find_voxel() instead of find_particle()
0ncorhynchus Nov 7, 2019
d087430
:art: Format VoxelSpaceBase.[ch]pp
0ncorhynchus Nov 14, 2019
c253770
:art: Format spatiocyte codes
0ncorhynchus Nov 14, 2019
7b04e0a
:recycle: Move get_value() and get_value_exact()
0ncorhynchus Nov 14, 2019
fa43c9e
:art: Format LatticeSpaces
0ncorhynchus Nov 14, 2019
a158164
:recycle: Use ranged-for-loop instead of iterator
0ncorhynchus Nov 21, 2019
6b2ba76
:recycle: Use auto for the return value of list_voxels()
0ncorhynchus Nov 21, 2019
28755ec
Merge pull request #434 from 0ncorhynchus/refactor_spatiocyte
0ncorhynchus Dec 12, 2019
eeafa95
:recycle: Isolate push_voxels() from VoxelSpaceBase
0ncorhynchus Nov 21, 2019
ef03b13
:bug: Make list_voxels() to show the real species
0ncorhynchus Nov 21, 2019
33912c2
:boom: Modify SpatiocyteWorld::list_voxels()
0ncorhynchus Nov 21, 2019
2e39bba
:boom: Do not use radius, D and loc from ParticleVoxel
0ncorhynchus Nov 21, 2019
e645363
:boom: Modify VoxelSpaceBase::list_voxels()
0ncorhynchus Nov 21, 2019
d197efb
:boom: Change the return type of find_voxel()
0ncorhynchus Nov 21, 2019
6d0eec5
:recycle: Modify VoxelSpaceBase::get_voxel_at()
0ncorhynchus Nov 21, 2019
3b5ae80
:boom: Remove radius and D from VoxelPool
0ncorhynchus Nov 21, 2019
1af6059
:recycle: Remove VoxelSpaceBase::get_voxel_pool()
0ncorhynchus Nov 28, 2019
c24f141
:recycle: Modify SpatiocyteWorld::update_voxel()
0ncorhynchus Nov 28, 2019
ca0995f
:recycle: Modify VoxelSpaceBase::update_voxel()
0ncorhynchus Nov 28, 2019
404a7b7
:fire: Remove ParticleVoxel completely!
0ncorhynchus Nov 28, 2019
cc26717
Merge pull request #435 from 0ncorhynchus/remove_particle_voxel
0ncorhynchus Dec 26, 2019
177e20e
:recycle: Add Voxel::get_neighbor_randomly()
0ncorhynchus Dec 26, 2019
7577208
:recycle: Add another Voxel::get_neighbor_randomly()
0ncorhynchus Dec 26, 2019
2dc40f8
:recycle: StepEvent2D uses Voxel::get_neighbor_randomly()
0ncorhynchus Dec 26, 2019
2eb1725
:recycle: Remove rng from args of get_neighbor_randomly()
0ncorhynchus Jan 9, 2020
41807bb
:recycle: Move functions for neighbor to SpatiocyteWorld
0ncorhynchus Jan 16, 2020
9f24487
:recycle: Change the types of intefaces_ and neighbors_
0ncorhynchus Jan 16, 2020
b4693e5
:recycle: Refactor add_structure() and remove is_inside()
0ncorhynchus Jan 16, 2020
02cdd43
:recycle: Change the arguments of gen_particle_from()
0ncorhynchus Jan 16, 2020
cb60782
:recycle: Add find_space_and_voxel_pool()
0ncorhynchus Jan 16, 2020
2e8516a
:recycle: Add find_space_and_molecule_pool()
0ncorhynchus Jan 16, 2020
f629617
:fire: Remove coordinate2voxel()
0ncorhynchus Jan 16, 2020
b889161
:bug: Fix bug around locating molecules
0ncorhynchus Jan 16, 2020
4759c2d
:fire: Remove SpatiocyteWorld::coordinate_type
0ncorhynchus Jan 16, 2020
d99f989
:bug: Fix num_voxels* and num_molecules*
0ncorhynchus Jan 23, 2020
de79eb5
:bug: Fix the bug of SpatiocyteWorld::add_molecules()
0ncorhynchus Jan 23, 2020
12ac0c8
:recycle: Refactor get_molecule_info()
0ncorhynchus Jan 23, 2020
aef1f5f
:bug: Get information from a model before add a space
0ncorhynchus Jan 23, 2020
e356131
:white_check_mark: Add test for get_molecule_info()
0ncorhynchus Jan 23, 2020
186b1ec
:bug: Fix get_location() with a vacant voxel
0ncorhynchus Jan 23, 2020
b0fe1aa
:bug: Fix SpatiocyteWorld::check_neighbor()
0ncorhynchus Jan 23, 2020
0f3e1c4
:bug: Fix reactions with OffLatticeSpace
0ncorhynchus Jan 23, 2020
67ed134
Merge pull request #445 from 0ncorhynchus/fix_offlattice
0ncorhynchus Jan 30, 2020
58affee
:recycle: Add a virtual function StepEvent::dimension()
0ncorhynchus Jan 30, 2020
7e0e265
:zap: Use template for StepEvent and some functions
0ncorhynchus Jan 30, 2020
6225f5f
:recycle: Add a model to a python test
0ncorhynchus Jan 30, 2020
2690cd2
:white_check_mark: Add a test for OffLattice
0ncorhynchus Feb 6, 2020
6f8cb4b
:twisted_rightwards_arrows: Cherry pick a commit for CircleCI
kozo2 Jan 2, 2020
d8c833d
:twisted_rightwards_arrows: Cherry pick another commit for CircleCI
0ncorhynchus Jan 30, 2020
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
8 changes: 5 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
parameters:
pyver:
type: enum
enum: ["cp35-cp35m", "cp36-cp36m", "cp37-cp37m"]
enum: ["cp35-cp35m", "cp36-cp36m", "cp37-cp37m", "cp38-cp38"]
steps:
- setup_remote_docker
- checkout
Expand All @@ -42,8 +42,7 @@ jobs:
name: Install auditwheel from source
command: |
git clone https://github.com/pypa/auditwheel.git
cd auditwheel && /opt/python/<< parameters.pyver >>/bin/python setup.py install
/opt/python/<< parameters.pyver >>/bin/pip install pyelftools
/opt/python/<< parameters.pyver >>/bin/python -m pip install ./auditwheel
- run:
name: Build E-Cell4
command: |
Expand All @@ -66,3 +65,6 @@ workflows:
- build:
name: build_py37
pyver: cp37-cp37m
- build:
name: build_py38
pyver: cp38-cp38
32 changes: 15 additions & 17 deletions ecell4/core/HCPLatticeSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,49 @@
#include <boost/numeric/interval/detail/msvc_rounding_control.hpp>
#endif

namespace ecell4 {
namespace ecell4
{

#ifdef WIN32_MSC
double rint(const double x)
{
return boost::numeric::interval_lib::detail::rint(x);
}

double round(const double x)
{
return floor(x + 0.5);
}
double round(const double x) { return floor(x + 0.5); }
#endif

void HCPLatticeSpace::set_lattice_properties(const Real3& edge_lengths, const bool is_periodic)
void HCPLatticeSpace::set_lattice_properties(const Real3 &edge_lengths,
const bool is_periodic)
{
//XXX: derived from SpatiocyteStepper::setLatticeProperties()
// XXX: derived from SpatiocyteStepper::setLatticeProperties()
HCP_L = voxel_radius_ / sqrt(3.0);
HCP_X = voxel_radius_ * sqrt(8.0 / 3.0); // Lx
HCP_Y = voxel_radius_ * sqrt(3.0); // Ly
HCP_Y = voxel_radius_ * sqrt(3.0); // Ly

const Real& lengthX = edge_lengths[0];
const Real& lengthY = edge_lengths[1];
const Real& lengthZ = edge_lengths[2];
const Real &lengthX = edge_lengths[0];
const Real &lengthY = edge_lengths[1];
const Real &lengthZ = edge_lengths[2];

col_size_ = (Integer)rint(lengthX / HCP_X);
layer_size_ = (Integer)rint(lengthY / HCP_Y);
row_size_ = (Integer)rint((lengthZ / 2) / voxel_radius_);

if (is_periodic)
{
// The number of voxels in each axis must be even for a periodic boundary.
// The number of voxels in each axis must be even for a periodic
// boundary.
col_size_ = (col_size_ % 2 == 0 ? col_size_ : col_size_ + 1);
layer_size_ = (layer_size_ % 2 == 0 ? layer_size_ : layer_size_ + 1);
row_size_ = (row_size_ % 2 == 0 ? row_size_ : row_size_ + 1);
}

edge_lengths_ = Real3(
col_size_ * HCP_X,
layer_size_ * HCP_Y,
row_size_ * voxel_radius_ * 2);
edge_lengths_ = Real3(col_size_ * HCP_X, layer_size_ * HCP_Y,
row_size_ * voxel_radius_ * 2);

row_size_ += 2;
layer_size_ += 2;
col_size_ += 2;
}

} // ecell4
} // namespace ecell4
94 changes: 37 additions & 57 deletions ecell4/core/HCPLatticeSpace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
namespace ecell4
{

class HCPLatticeSpace
: public VoxelSpaceBase
class HCPLatticeSpace : public VoxelSpaceBase
{
public:

typedef VoxelSpaceBase base_type;

public:

HCPLatticeSpace(const Real3& edge_lengths, const Real& voxel_radius, const bool is_periodic)
HCPLatticeSpace(const Real3 &edge_lengths, const Real &voxel_radius,
const bool is_periodic)
: base_type(voxel_radius)
{
set_lattice_properties(edge_lengths, is_periodic);
Expand All @@ -26,99 +24,86 @@ class HCPLatticeSpace
; // do nothing
}

virtual void reset(const Real3& edge_lengths, const Real& voxel_radius, const bool is_periodic)
virtual void reset(const Real3 &edge_lengths, const Real &voxel_radius,
const bool is_periodic)
{
voxel_radius_ = voxel_radius;

set_lattice_properties(edge_lengths, is_periodic);
}

void set_lattice_properties(const Real3& edge_lengths, const bool is_periodic);
void set_lattice_properties(const Real3 &edge_lengths,
const bool is_periodic);

/**
* Primitives
*/

const Real3& edge_lengths() const
{
return edge_lengths_;
}
const Real3 &edge_lengths() const { return edge_lengths_; }

virtual const Integer col_size() const
{
return col_size_ - 2;
}
virtual const Integer col_size() const { return col_size_ - 2; }

virtual const Integer row_size() const
{
return row_size_ - 2;
}
virtual const Integer row_size() const { return row_size_ - 2; }

virtual const Integer layer_size() const
{
return layer_size_ - 2;
}
virtual const Integer layer_size() const { return layer_size_ - 2; }

/**
Coordinate transformations
*/
coordinate_type global2coordinate(const Integer3& global) const
coordinate_type global2coordinate(const Integer3 &global) const
{
const Integer3 g(global.col + 1, global.row + 1, global.layer + 1);
return g.row + row_size_ * (g.col + col_size_ * g.layer);
}

Integer3 coordinate2global(const coordinate_type& coord) const
Integer3 coordinate2global(const coordinate_type &coord) const
{
const Integer NUM_COLROW(row_size_ * col_size_);
const Integer LAYER(coord / NUM_COLROW);
const Integer SURPLUS(coord - LAYER * NUM_COLROW);
const Integer COL(SURPLUS / row_size_);
const Integer3 global(COL, SURPLUS - COL * row_size_, LAYER);
const Integer3 retval(
global.col - 1, global.row - 1, global.layer - 1);
const Integer3 retval(global.col - 1, global.row - 1, global.layer - 1);
return retval;
}

Real3 coordinate2position(const coordinate_type& coord) const
Real3 coordinate2position(const coordinate_type &coord) const
{
return global2position(coordinate2global(coord));
}

coordinate_type position2coordinate(const Real3& pos) const
coordinate_type position2coordinate(const Real3 &pos) const
{
return global2coordinate(position2global(pos));
}

Real3 global2position(const Integer3& global) const
Real3 global2position(const Integer3 &global) const
{
// the center point of a voxel
const Real3 pos(
global.col * HCP_X,
(global.col % 2) * HCP_L + HCP_Y * global.layer,
(global.row * 2 + (global.layer + global.col) % 2)
* voxel_radius_);
global.col * HCP_X, (global.col % 2) * HCP_L + HCP_Y * global.layer,
(global.row * 2 + (global.layer + global.col) % 2) * voxel_radius_);
return pos;
}

Integer3 position2global(const Real3& pos) const
Integer3 position2global(const Real3 &pos) const
{
const Integer col(round(pos[0] / HCP_X));
const Integer layer(round((pos[1] - (col % 2) * HCP_L) / HCP_Y));
const Integer row(round(
(pos[2] / voxel_radius_ - ((layer + col) % 2)) / 2));
const Integer row(
round((pos[2] / voxel_radius_ - ((layer + col) % 2)) / 2));
const Integer3 global(col, row, layer);
return global;
}

Integer num_neighbors(const coordinate_type& coord) const
Integer num_neighbors(const coordinate_type &coord) const
{
if (!is_inside(coord)) return 0;
if (!is_inside(coord))
return 0;
return 12;
}

coordinate_type periodic_transpose(
const coordinate_type& coord) const
coordinate_type periodic_transpose(const coordinate_type &coord) const
{
Integer3 global(coordinate2global(coord));

Expand All @@ -128,15 +113,15 @@ class HCPLatticeSpace

global.col = global.col < 0 ? global.col + col_size() : global.col;
global.row = global.row < 0 ? global.row + row_size() : global.row;
global.layer = global.layer < 0 ? global.layer + layer_size() : global.layer;
global.layer =
global.layer < 0 ? global.layer + layer_size() : global.layer;

return global2coordinate(global);
}

protected:

coordinate_type get_neighbor_(
const coordinate_type& coord, const Integer& nrand) const
coordinate_type get_neighbor_(const coordinate_type &coord,
const Integer &nrand) const
{
const Integer NUM_COLROW(col_size_ * row_size_);
const Integer NUM_ROW(row_size_);
Expand Down Expand Up @@ -177,24 +162,20 @@ class HCPLatticeSpace
}

public:

bool is_in_range(const coordinate_type& coord) const
bool is_in_range(const coordinate_type &coord) const
{
return coord >= 0 && coord < row_size_ * col_size_ * layer_size_;
}

virtual bool is_inside(const coordinate_type& coord) const
virtual bool is_inside(const coordinate_type &coord) const
{
const Integer3 global(coordinate2global(coord));
return global.col >= 0 && global.col < col_size()
&& global.row >= 0 && global.row < row_size()
&& global.layer >= 0 && global.layer < layer_size();
return global.col >= 0 && global.col < col_size() && global.row >= 0 &&
global.row < row_size() && global.layer >= 0 &&
global.layer < layer_size();
}

virtual Integer size() const
{
return row_size_ * col_size_ * layer_size_;
}
virtual Integer size() const { return row_size_ * col_size_ * layer_size_; }

virtual Integer3 shape() const
{
Expand All @@ -207,12 +188,11 @@ class HCPLatticeSpace
}

protected:

Real3 edge_lengths_;
Real HCP_L, HCP_X, HCP_Y;
Integer row_size_, layer_size_, col_size_;
};

} // ecell4
} // namespace ecell4

#endif /* ECELL4_LATTICE_SPACE_BASE_HPP */
Loading