Skip to content

Commit

Permalink
Add OB_RANDOM_SEED environment variable to specify seed for PRNG
Browse files Browse the repository at this point in the history
  • Loading branch information
e-kwsm committed Jun 16, 2020
1 parent f535334 commit 301390e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions doc/obabel.1
Expand Up @@ -341,6 +341,11 @@ Conversion from a SMI file in STDIN to a Mol2 file written to STDOUT:
.Dl "obabel \-ismi \-omol2"
Split a multi-molecule file into new1.smi, new2.smi, etc.:
.Dl "obabel infile.mol -Onew.smi \-m"
.Sh ENVIRONMENT
.Bl -tag -width flag
.It Ev OB_RANDOM_SEED
Specify seed for pseudo random number generator.
If not specified, random seed is used.
.Sh SEE ALSO
.Xr obenergy 1 ,
.Xr obfit 1 ,
Expand Down
5 changes: 5 additions & 0 deletions doc/obdistgen.1
Expand Up @@ -14,6 +14,11 @@ Generates SDFs with distance geometry.
.Pp
Generate rough 3D coordinates for molecule.smi and write
it to molecule.sdf
.Sh ENVIRONMENT
.Bl -tag -width flag
.It Ev OB_RANDOM_SEED
Specify seed for pseudo random number generator.
If not specified, random seed is used.
.Sh SEE ALSO
.Xr obgen 1 .
.Pp
Expand Down
5 changes: 5 additions & 0 deletions doc/obgen.1
Expand Up @@ -32,6 +32,11 @@ Generate 3D coordinates for the molecule(s) in file test.smi:
Generate 3D coordinates for the molecule(s) in file test.smi using the
UFF forcefield:
.Dl "obgen -ff UFF test.smi"
.Sh ENVIRONMENT
.Bl -tag -width flag
.It Ev OB_RANDOM_SEED
Specify seed for pseudo random number generator.
If not specified, random seed is used.
.Sh SEE ALSO
.Xr obabel 1 ,
.Xr obminimize 1 ,
Expand Down
7 changes: 7 additions & 0 deletions src/rand.cpp
Expand Up @@ -19,6 +19,8 @@ GNU General Public License for more details.

#include "rand.h"

#include <cstdlib>

#if TIME_WITH_SYS_TIME
#include <sys/time.h>
#include <ctime>
Expand All @@ -36,6 +38,11 @@ namespace OpenBabel

void OBRandom::Reset()
{
auto ob_random_seed = std::getenv("OB_RANDOM_SEED");
if (ob_random_seed) {
this->Seed(std::atoll(ob_random_seed));
return;
}
#if defined(WIN32) || defined(__MINGW32__)
// for VC++ do it this way
time_t ltime;
Expand Down

0 comments on commit 301390e

Please sign in to comment.