Skip to content

Commit 414b8c9

Browse files
authored
Merge pull request #319 from StochSS/develop
Release v1.1.1
2 parents 7da3e17 + dbe38e2 commit 414b8c9

File tree

6 files changed

+58
-43
lines changed

6 files changed

+58
-43
lines changed

spatialpy/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# @website https://github.com/StochSS/SpatialPy
2222
# =============================================================================
2323

24-
__version__ = '1.1.0'
24+
__version__ = '1.1.1'
2525
__title__ = 'SpatialPy'
2626
__description__ = 'Python Interface for Spatial Stochastic Biochemical Simulations'
2727
__url__ = 'https://spatialpy.github.io/SpatialPy/'

spatialpy/core/reaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def _create_mass_action(self):
293293
reactant = reactant.name
294294
# Case 1: 2X -> Y
295295
if stoichiometry == 2:
296-
propensity_function = f"0.5 * {propensity_function} * {reactant} * ({reactant} - 1) / vol"
296+
propensity_function = f"{propensity_function} * {reactant} * ({reactant} - 1) / vol"
297297
ode_propensity_function += f" * {reactant} * {reactant}"
298298
else:
299299
# Case 3: X1, X2 -> Y;

spatialpy/solvers/c_base/ssa_sdpd-c-simulation-engine/src/model.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ Based on a Matlab program by Bruno Jacob (UCSB)
2525
This program is distributed under the terms of the GNU GENERAL PUBLIC LICENSE Version 3.
2626
See the file LICENSE.txt for details.
2727
***************************************************************************************** */
28-
#include <math.h>
28+
#if defined(WIN32) || defined(_WIN32) || defined(__MINGW32__)
29+
#define _USE_MATH_DEFINES
30+
#endif
31+
#include <cmath>
2932
#include <stdio.h>
3033
#include <stdlib.h>
3134

spatialpy/solvers/c_base/ssa_sdpd-c-simulation-engine/src/particle.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ See the file LICENSE.txt for details.
2626

2727
#include <stdlib.h>
2828
#include <stdio.h>
29-
#include <math.h>
29+
#if defined(WIN32) || defined(_WIN32) || defined(__MINGW32__)
30+
#define _USE_MATH_DEFINES
31+
#endif
32+
#include <cmath>
3033
#include <cstdlib>
3134
#include <vector>
3235
#include <queue>
@@ -84,13 +87,13 @@ namespace Spatialpy{
8487

8588
void Particle::check_particle_nan(){
8689
if(
87-
isnan(x[0]) || !isfinite(x[0]) ||
88-
isnan(x[1]) || !isfinite(x[1]) ||
89-
isnan(x[2]) || !isfinite(x[2]) ||
90-
isnan(v[0]) || !isfinite(v[0]) ||
91-
isnan(v[1]) || !isfinite(v[1]) ||
92-
isnan(v[2]) || !isfinite(v[2]) ||
93-
isnan(rho) || !isfinite(rho) ){
90+
std::isnan(x[0]) || !std::isfinite(x[0]) ||
91+
std::isnan(x[1]) || !std::isfinite(x[1]) ||
92+
std::isnan(x[2]) || !std::isfinite(x[2]) ||
93+
std::isnan(v[0]) || !std::isfinite(v[0]) ||
94+
std::isnan(v[1]) || !std::isfinite(v[1]) ||
95+
std::isnan(v[2]) || !std::isfinite(v[2]) ||
96+
std::isnan(rho) || !std::isfinite(rho) ){
9497
printf("ERROR: nan/inf detected!!!\n");
9598
printf("number of neighbors: %li\n", neighbors.size()) ;
9699
printf("id=%i\n",id);
@@ -183,7 +186,7 @@ namespace Spatialpy{
183186
// Eq 28 of Drawert et al 2019, Tartakovsky et. al., 2007, JCP
184187
double D_i_j = -2.0*(mass*neighbor->mass)/(mass+neighbor->mass)*(rho+neighbor->rho)/(rho*neighbor->rho) * r2 * wfd / (r2+0.01*h*h);
185188

186-
if(isnan(D_i_j)){
189+
if(std::isnan(D_i_j)){
187190
printf("Got NaN calculating D_i_j for me=%i, neighbor=%i\n",id, neighbor->id);
188191
printf("system->dimension=%i ",system->dimension);
189192
printf("r2=%e ",r2);

spatialpy/solvers/solver.py

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -470,41 +470,50 @@ def compile(self, debug=False, profile=False):
470470
self.__create_propensity_file(stoich_matrix, dep_graph, file_name=self.prop_file_name)
471471

472472
# Build the solver
473+
for make_exe_location in ["make", "mingw32-make"]:
474+
make_exe = shutil.which("make")
475+
if make_exe is not None:
476+
break
477+
if make_exe is None:
478+
raise SimulationError("Make executable could not be found")
473479
makefile = self.spatialpy_rootdir+'/build/Makefile'
474480
makefile_ann = self.spatialpy_rootdir+'/external/ANN/src/Makefile.spatialpy'
475-
cmd_list = ['cd', self.core_dir, '&&',
476-
'make', '-f' , makefile_ann,
477-
'ROOTINC="' + self.spatialpy_rootinc+'"',
478-
'&&',
479-
'make', 'CORE', '-f', makefile,
480-
'ROOT="' + self.spatialpy_rootparam+'"',
481-
'ROOTINC="' + self.spatialpy_rootinc+'"',
482-
'BUILD='+self.core_dir, '&&'
483-
'cd', self.build_dir, '&&', 'make', '-I', self.core_dir, '-f', makefile,
484-
'ROOT="' + self.spatialpy_rootparam+'"',
485-
'ROOTINC="' + self.spatialpy_rootinc+'"',
486-
'COREDIR="' + self.core_dir + '"',
487-
'MODEL=' + self.prop_file_name, 'BUILD='+self.build_dir]
481+
482+
cmd_ann = [
483+
make_exe, '-d', '-C', self.core_dir, '-f', makefile_ann,
484+
f'ROOTINC={self.spatialpy_rootinc}',
485+
]
486+
cmd_core = [
487+
make_exe, '-d', '-C', self.core_dir, 'CORE', '-f', makefile,
488+
f'ROOT={self.spatialpy_rootparam}',
489+
f'ROOTINC={self.spatialpy_rootinc}',
490+
f'BUILD={self.core_dir}',
491+
]
492+
cmd_build = [
493+
make_exe, '-d', '-C', self.build_dir, '-I', self.core_dir, '-f', makefile,
494+
'ROOT=' + self.spatialpy_rootparam,
495+
'ROOTINC=' + self.spatialpy_rootinc,
496+
'COREDIR=' + self.core_dir,
497+
'MODEL=' + self.prop_file_name, 'BUILD='+self.build_dir
498+
]
488499
if profile:
489-
cmd_list.append('GPROFFLAG=-pg')
500+
cmd_build.append('GPROFFLAG=-pg')
490501
if profile or debug:
491-
cmd_list.append('GDB_FLAG=-g')
492-
cmd = " ".join(cmd_list)
502+
cmd_build.append('GDB_FLAG=-g')
493503
if self.debug_level > 1:
504+
cmd = " && ".join([*cmd_ann, *cmd_core, *cmd_build])
494505
print(f"cmd: {cmd}\n")
495506
try:
496-
with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) as handle:
497-
stdout, _ = handle.communicate()
498-
return_code = handle.wait()
499-
if return_code != 0:
500-
try:
501-
print(stdout.decode("utf-8"))
502-
except Exception:
503-
pass
504-
raise SimulationError(f"Compilation of solver failed, return_code={return_code}")
505-
507+
for cmd_target in [cmd_ann, cmd_core, cmd_build]:
508+
result = subprocess.check_output(cmd_target, stderr=subprocess.STDOUT)
506509
if self.debug_level > 1:
507-
print(stdout.decode("utf-8"))
510+
print(result.stdout.decode("utf-8"))
511+
except subprocess.CalledProcessError as err:
512+
try:
513+
print(err.stdout.decode("utf-8"))
514+
except Exception:
515+
pass
516+
raise SimulationError(f"Compilation of solver failed, return_code={result.return_code}")
508517
except OSError as err:
509518
print(f"Error, execution of compilation raised an exception: {err}")
510519
print(f"cmd = {cmd}")
@@ -559,7 +568,7 @@ def run(self, number_of_trajectories=1, seed=None, timeout=None,
559568
result = Result(self.model, outfile)
560569
if self.debug_level >= 1:
561570
print(f"Running simulation. Result dir: {outfile}")
562-
solver_cmd = f'cd {outfile};{os.path.join(self.build_dir, self.executable_name)}'
571+
solver_cmd = os.path.join(self.build_dir, self.executable_name)
563572

564573
if number_of_threads is not None:
565574
solver_cmd += " -t " + str(number_of_threads)
@@ -573,7 +582,7 @@ def run(self, number_of_trajectories=1, seed=None, timeout=None,
573582
start = time.monotonic()
574583
return_code = None
575584
try:
576-
with subprocess.Popen(solver_cmd, shell=True,
585+
with subprocess.Popen(solver_cmd, cwd=outfile, shell=True,
577586
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
578587
start_new_session=True) as process:
579588
try:

test/unit_tests/test_reaction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ def test__create_mass_action__2X_to_Y(self):
450450
self.valid_ma_reaction.reactants = {"X": 2}
451451
self.valid_ma_reaction.products = {"Y": 1}
452452
self.valid_ma_reaction._create_mass_action()
453-
self.assertEqual(self.valid_ma_reaction.propensity_function, "((((0.5*k1)*X)*(X-1))/vol)")
453+
self.assertEqual(self.valid_ma_reaction.propensity_function, "(((k1*X)*(X-1))/vol)")
454454
self.assertEqual(self.valid_ma_reaction.ode_propensity_function, "((k1*X)*X)")
455455

456456
def test__create_mass_action__species_obj_reactant(self):
@@ -581,7 +581,7 @@ def test_add_reactant__massaction_reaction_stoich_0_to_2(self):
581581
self.valid_ma_reaction.add_reactant("X", 2)
582582
self.assertIn("X", self.valid_ma_reaction.reactants)
583583
self.assertEqual(self.valid_ma_reaction.reactants["X"], 2)
584-
self.assertEqual(self.valid_ma_reaction.propensity_function, "((((0.5*k1)*X)*(X-1))/vol)")
584+
self.assertEqual(self.valid_ma_reaction.propensity_function, "(((k1*X)*(X-1))/vol)")
585585
self.assertEqual(self.valid_ma_reaction.ode_propensity_function, "((k1*X)*X)")
586586

587587
def test_add_reactant__invalid_species(self):

0 commit comments

Comments
 (0)