-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
371 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
from _accept_test_cpp import MetropolisTest | ||
from _conf_test_cpp import CheckSphericalContainer | ||
from _conf_test_cpp import CheckSphericalContainerConfig | ||
from _conf_test_cpp import CheckSphericalContainerConfig, ConfTestOR | ||
from _takestep_cpp import RandomCoordsDisplacement, SampleGaussian | ||
from _takestep_cpp import GaussianCoordsDisplacement, ParticlePairSwap | ||
from _takestep_cpp import TakeStepPattern, TakeStepProbabilities | ||
from _takestep_cpp import UniformSphericalSampling, UniformCubicSampling | ||
from _monte_carlo_cpp import _BaseMCRunner | ||
from _action_cpp import RecordEnergyHistogram, RecordEnergyTimeseries, RecordPairDistHistogram, RecordLowestEValueTimeseries, RecordDisplacementPerParticleTimeseries | ||
from _action_cpp import RecordCoordsTimeseries | ||
from _nullpotential_cpp import NullPotential | ||
from mcrunner import Metropolis_MCrunner | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from _utils import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from __future__ import division | ||
import numpy as np | ||
import pandas as pd | ||
|
||
def write_2d_array_to_hf5(array, key, path): | ||
""" | ||
this function can be used to dump any 2d array to a hf5 database | ||
use this to dump a trajectory to a database from python | ||
""" | ||
assert array.ndim == 2 | ||
nind , ncol = array.shape | ||
ind = [i for i in xrange(nind)] | ||
col = [i for i in xrange(ncol)] | ||
df = pd.DataFrame(np.array(array), index=ind, columns=col) | ||
df.to_hdf(path, key) | ||
|
||
def read_hf5_to_2d_array(path, key): | ||
""" | ||
read a 2d array from a hf5 database | ||
""" | ||
df = pd.read_hdf(path, key) | ||
array = np.array(df.values) | ||
return array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "mcpele/conf_test_OR.h" | ||
|
||
namespace mcpele { | ||
|
||
ConfTestOR::ConfTestOR(){} | ||
|
||
void ConfTestOR::add_test(std::shared_ptr<ConfTest> test_input) | ||
{ | ||
m_tests.push_back(test_input); | ||
m_tests.swap(m_tests); | ||
} | ||
|
||
bool ConfTestOR::conf_test(pele::Array<double> &trial_coords, MC * mc) | ||
{ | ||
if (m_tests.size() == 0) { | ||
throw std::runtime_error("ConfTestOR::conf_test: no conf test specified"); | ||
} | ||
for(auto & test : m_tests){ | ||
bool result = test->conf_test(trial_coords, mc); | ||
if (result){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
} // namespace mcpele |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef _MCPELE_CONF_TEST_OR_H__ | ||
#define _MCPELE_CONF_TEST_OR_H__ | ||
|
||
#include <vector> | ||
#include <random> | ||
|
||
#include "mc.h" | ||
|
||
namespace mcpele { | ||
|
||
/** | ||
* Create union of two configurational tests, | ||
* it is sufficient for one of them to be true in order to pass the overall test. | ||
* | ||
*/ | ||
class ConfTestOR : public ConfTest { | ||
private: | ||
std::vector<std::shared_ptr<ConfTest> > m_tests; | ||
public: | ||
virtual ~ConfTestOR(){} | ||
ConfTestOR(); | ||
void add_test(std::shared_ptr<ConfTest> test_input); | ||
bool conf_test(pele::Array<double> &trial_coords, MC * mc); | ||
}; | ||
|
||
} // namespace mcpele | ||
|
||
#endif // #ifndef _MCPELE_CONF_TEST_OR_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef _MCPELE_RECORD_COORDS_TIMESERIES_H__ | ||
#define _MCPELE_RECORD_COORDS_TIMESERIES_H__ | ||
|
||
#include "record_vector_timeseries.h" | ||
|
||
namespace mcpele { | ||
|
||
class RecordCoordsTimeseries : public RecordVectorTimeseries { | ||
private: | ||
pele::Array<double> m_mcv, m_mcv2; | ||
const size_t m_ndof; | ||
size_t m_count; | ||
double m_update_average(double avg, double x); | ||
void m_update_mean_coord_vector(pele::Array<double> &new_coords); | ||
public: | ||
RecordCoordsTimeseries(const size_t ndof, const size_t record_every, const size_t eqsteps); | ||
virtual ~RecordCoordsTimeseries() {} | ||
virtual pele::Array<double> get_recorded_vector(pele::Array<double> &coords, | ||
const double energy, const bool accepted, MC* mc) { return coords; } | ||
virtual void action(pele::Array<double> &coords, double energy, bool accepted, MC* mc); | ||
pele::Array<double> get_mean_coordinate_vector(){return m_mcv.copy();} | ||
pele::Array<double> get_mean2_coordinate_vector(){return m_mcv2.copy();} | ||
pele::Array<double> get_variance_coordinate_vector() | ||
{ | ||
pele::Array<double> var = m_mcv2.copy(); | ||
for(size_t i=0; i<m_ndof; ++i){ | ||
var[i] -= m_mcv[i]*m_mcv[i]; | ||
} | ||
return var.copy(); | ||
} | ||
size_t get_count(){return m_count;} | ||
}; | ||
|
||
} // namespace mcpele | ||
|
||
#endif // #ifndef _MCPELE_RECORD_COORDS_TIMESERIES_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#ifndef _MCPELE_RECORD_VECTOR_TIMESERIES_H__ | ||
#define _MCPELE_RECORD_VECTOR_TIMESERIES_H__ | ||
|
||
#include "mc.h" | ||
#include <deque> | ||
#include <cstdlib> | ||
|
||
namespace mcpele { | ||
|
||
/** | ||
* Record vector time series, every record_every-th step. | ||
*/ | ||
class RecordVectorTimeseries : public Action { | ||
protected: | ||
const size_t m_record_every, m_eqsteps; | ||
std::deque<pele::Array<double>> m_time_series; | ||
void m_record_vector_value(pele::Array<double> input) | ||
{ | ||
try{ | ||
m_time_series.push_back(input.copy()); | ||
} | ||
catch(std::bad_alloc &ba){ | ||
std::cerr<< "mcpele::RecordVectorTimeseries: bad_alloc caught: " << ba.what() << std::endl; | ||
std::exit(EXIT_FAILURE); | ||
} | ||
} | ||
public: | ||
RecordVectorTimeseries(const size_t record_every, const size_t eqsteps); | ||
virtual ~RecordVectorTimeseries(){} | ||
virtual void action(pele::Array<double> &coords, double energy, bool accepted, MC* mc); | ||
virtual pele::Array<double> get_recorded_vector(pele::Array<double> &coords, const double energy, const bool accepted, MC* mc)=0; | ||
std::deque<pele::Array<double>> get_time_series() | ||
{ | ||
m_time_series.shrink_to_fit(); | ||
return m_time_series; | ||
} | ||
void clear() { m_time_series.clear(); } | ||
size_t get_record_every(){return m_record_every;} | ||
}; | ||
|
||
} // namespace mcpele | ||
|
||
#endif // #ifndef _MCPELE_RECORD_VECTOR_TIMESERIES_H__ |
Oops, something went wrong.