![]() |
ForceBalance API
1.3
Automated optimization of force fields and empirical potentials
|
Classes | |
| class | LineChunker |
| class | RawFileHandler |
| Exactly like FileHandler, except no newline character is printed at the end of each message. More... | |
| class | RawStreamHandler |
| Exactly like StreamHandler, except no newline character is printed at the end of each message. More... | |
Functions | |
| def | pvec1d (vec1d, precision=1, format="e", loglevel=INFO) |
| Printout of a 1-D vector. More... | |
| def | astr (vec1d, precision=4) |
| Write an array to a string so we can use it to key a dictionary. More... | |
| def | pmat2d (mat2d, precision=1, format="e", loglevel=INFO) |
| Printout of a 2-D array. More... | |
| def | grouper (iterable, n) |
| Collect data into fixed-length chunks or blocks. More... | |
| def | encode (l) |
| def | segments (e) |
| def | commadash (l) |
| def | uncommadash (s) |
| def | natural_sort (l) |
| Return a natural sorted list. More... | |
| def | printcool (text, sym="#", bold=False, color=2, ansi=None, bottom='-', minwidth=50, center=True, sym2="=") |
| Cool-looking printout for slick formatting of output. More... | |
| def | printcool_dictionary (Dict, title="Dictionary Keys : Values", bold=False, color=2, keywidth=25, topwidth=50, center=True, leftpad=0) |
| See documentation for printcool; this is a nice way to print out keys/values in a dictionary. More... | |
| def | isint (word) |
| ONLY matches integers! If you have a decimal point? None shall pass! More... | |
| def | isfloat (word) |
| Matches ANY number; it can be a decimal, scientific notation, what have you CAUTION - this will also match an integer. More... | |
| def | isdecimal (word) |
| Matches things with a decimal only; see isint and isfloat. More... | |
| def | floatornan (word) |
| Returns a big number if we encounter NaN. More... | |
| def | col (vec) |
| Given any list, array, or matrix, return a 1-column 2D array. More... | |
| def | row (vec) |
| Given any list, array, or matrix, return a 1-row 2D array. More... | |
| def | flat (vec) |
| Given any list, array, or matrix, return a single-index array. More... | |
| def | est124 (val) |
| Given any positive floating point value, return a value [124]e+xx that is closest to it in the log space. More... | |
| def | est1234568 (val) |
| Given any positive floating point value, return a value [1234568]e+xx that is closest to it in the log space. More... | |
| def | monotonic (arr, start, end) |
| def | monotonic_decreasing (arr, start=None, end=None, verbose=False) |
| Return the indices of an array corresponding to strictly monotonic decreasing behavior. More... | |
| def | orthogonalize (vec1, vec2) |
| Given two vectors vec1 and vec2, project out the component of vec1 that is along the vec2-direction. More... | |
| def | invert_svd (X, thresh=1e-12) |
| Invert a matrix using singular value decomposition. More... | |
| def | get_least_squares (x, y, w=None, thresh=1e-12) |
| def | statisticalInefficiency (A_n, B_n=None, fast=False, mintime=3, warn=True) |
| Compute the (cross) statistical inefficiency of (two) timeseries. More... | |
| def | mean_stderr (ts) |
| Return mean and standard deviation of a time series ts. More... | |
| def | multiD_statisticalInefficiency (A_n, B_n=None, fast=False, mintime=3, warn=True) |
| def | lp_dump (obj, fnm, protocol=0) |
| Write an object to a zipped pickle file specified by the path. More... | |
| def | lp_load (fnm) |
| Read an object from a bzipped file specified by the path. More... | |
| def | getWorkQueue () |
| def | getWQIds () |
| def | createWorkQueue (wq_port, debug=True, name=package) |
| def | destroyWorkQueue () |
| def | queue_up (wq, command, input_files, output_files, tag=None, tgt=None, verbose=True, print_time=60) |
| Submit a job to the Work Queue. More... | |
| def | queue_up_src_dest (wq, command, input_files, output_files, tag=None, tgt=None, verbose=True, print_time=60) |
| Submit a job to the Work Queue. More... | |
| def | wq_wait1 (wq, wait_time=10, wait_intvl=1, print_time=60, verbose=False) |
| This function waits ten seconds to see if a task in the Work Queue has finished. More... | |
| def | wq_wait (wq, wait_time=10, wait_intvl=10, print_time=60, verbose=False) |
| This function waits until the work queue is completely empty. More... | |
| def | click () |
| Stopwatch function for timing. More... | |
| def | splitall (path) |
| def | bak (path, dest=None, cwd=None, start=1) |
| def | onefile (fnm=None, ext=None, err=False) |
| def | listfiles (fnms=None, ext=None, err=False, dnm=None) |
| def | extract_tar (tarfnm, fnms, force=False) |
| Extract a list of files from .tar archive with any compression. More... | |
| def | GoInto (Dir) |
| def | allsplit (Dir) |
| def | Leave (Dir) |
| def | MissingFileInspection (fnm) |
| def | wopen (dest, binary=False) |
| If trying to write to a symbolic link, remove it first. More... | |
| def | LinkFile (src, dest, nosrcok=False) |
| def | CopyFile (src, dest) |
| def | link_dir_contents (abssrcdir, absdestdir) |
| def | remove_if_exists (fnm) |
| Remove the file if it exists (doesn't return an error). More... | |
| def | which (fnm) |
| def | copy_tree_over (src, dest) |
| Copy a source directory tree to a destination directory tree, overwriting files as necessary. More... | |
| def | warn_press_key (warning, timeout=10) |
| def | warn_once (warning, warnhash=None) |
| Prints a warning but will only do so once in a given run. More... | |
| def | concurrent_map (func, data) |
| Similar to the bultin function map(). More... | |
Variables | |
| string | package = "ForceBalance" |
| logger = getLogger(__name__) | |
| handler = RawStreamHandler() | |
| bool | HaveBZ2 = True |
| bool | HaveGZ = True |
| rootdir = os.path.dirname(os.path.abspath(__file__)) | |
| float | kb = 0.008314462618 |
| Boltzmann constant in kJ mol^-1 k^-1. More... | |
| float | kb_si = 1.380649e-23 |
| float | bohr2ang = 0.529177210903 |
| float | ang2bohr = 1.0 / bohr2ang |
| float | au2kcal = 627.5094740630558 |
| float | kcal2au = 1.0 / au2kcal |
| float | au2kj = 2625.4996394798254 |
| float | kj2au = 1.0 / au2kj |
| float | grad_au2gmx = 49614.75258920567 |
| float | grad_gmx2au = 1.0 / grad_au2gmx |
| float | au2evang = 51.422067476325886 |
| float | evang2au = 1.0 / au2evang |
| int | c_lightspeed = 299792458. |
| float | hbar = 1.054571817e-34 |
| float | avogadro = 6.02214076e23 |
| float | au_mass = 9.1093837015e-31 |
| float | amu_mass = 1.66053906660e-27 |
| float | amu2au = amu_mass / au_mass |
| int | cm2au = 100 * c_lightspeed * (2*np.pi*hbar) * avogadro / 1000 / au2kj |
| float | ambervel2au = 9.349961132249932e-04 |
| float | eqcgmx = au2kj |
| Q-Chem to GMX unit conversion for energy. More... | |
| float | fqcgmx = -grad_au2gmx |
| Q-Chem to GMX unit conversion for force. More... | |
| WORK_QUEUE = None | |
| WQIDS = defaultdict(list) | |
| list | specific_lst |
| specific_dct = dict(list(itertools.chain(*[[(j,i[1]) for j in i[0]] for i in specific_lst]))) | |
| def src.nifty.astr | ( | vec1d, | |
precision = 4 |
|||
| ) |
| def src.nifty.bak | ( | path, | |
dest = None, |
|||
cwd = None, |
|||
start = 1 |
|||
| ) |
| def src.nifty.col | ( | vec | ) |
| def src.nifty.commadash | ( | l | ) |
| def src.nifty.concurrent_map | ( | func, | |
| data | |||
| ) |
| def src.nifty.copy_tree_over | ( | src, | |
| dest | |||
| ) |
| def src.nifty.CopyFile | ( | src, | |
| dest | |||
| ) |
| def src.nifty.createWorkQueue | ( | wq_port, | |
debug = True, |
|||
name = package |
|||
| ) |
| def src.nifty.est1234568 | ( | val | ) |
| def src.nifty.est124 | ( | val | ) |
| def src.nifty.extract_tar | ( | tarfnm, | |
| fnms, | |||
force = False |
|||
| ) |
Extract a list of files from .tar archive with any compression.
The file is extracted to the base folder of the archive.
tarfnm : Name of the archive file. fnms : str or list File names to be extracted. force : bool, optional If true, then force extraction of file even if they already exist on disk.
| def src.nifty.flat | ( | vec | ) |
| def src.nifty.floatornan | ( | word | ) |
| def src.nifty.get_least_squares | ( | x, | |
| y, | |||
w = None, |
|||
thresh = 1e-12 |
|||
| ) |
| [in] | X | (2-D array) An array of X-values (see above) |
| [in] | Y | (array) An array of Y-values (only used in getting the least squares coefficients) |
| [in] | w | (array) An array of weights, hopefully normalized to one. |
| [out] | Beta | The least-squares coefficients |
| [out] | Hat | The hat matrix that takes linear combinations of data y-values to give fitted y-values (weights) |
| [out] | yfit | The fitted y-values |
| [out] | MPPI | The Moore-Penrose pseudoinverse (multiply by Y to get least-squares coefficients, multiply by dY/dk to get derivatives of least-squares coefficients) |
Definition at line 662 of file nifty.py.
| def src.nifty.grouper | ( | iterable, | |
| n | |||
| ) |
| def src.nifty.invert_svd | ( | X, | |
thresh = 1e-12 |
|||
| ) |
Invert a matrix using singular value decomposition.
| [in] | X | The 2-D NumPy array containing the matrix to be inverted |
| [in] | thresh | The SVD threshold; eigenvalues below this are not inverted but set to zero |
| def src.nifty.isdecimal | ( | word | ) |
Matches things with a decimal only; see isint and isfloat.
| [in] | word | String (for instance, '123', '153.0', '2.', '-354') |
Definition at line 418 of file nifty.py.
| def src.nifty.isfloat | ( | word | ) |
Matches ANY number; it can be a decimal, scientific notation, what have you CAUTION - this will also match an integer.
| [in] | word | String (for instance, '123', '153.0', '2.', '-354') |
| def src.nifty.isint | ( | word | ) |
| def src.nifty.Leave | ( | Dir | ) |
| def src.nifty.LinkFile | ( | src, | |
| dest, | |||
nosrcok = False |
|||
| ) |
| def src.nifty.listfiles | ( | fnms = None, |
|
ext = None, |
|||
err = False, |
|||
dnm = None |
|||
| ) |
| def src.nifty.lp_dump | ( | obj, | |
| fnm, | |||
protocol = 0 |
|||
| ) |
| def src.nifty.lp_load | ( | fnm | ) |
| def src.nifty.mean_stderr | ( | ts | ) |
| def src.nifty.monotonic_decreasing | ( | arr, | |
start = None, |
|||
end = None, |
|||
verbose = False |
|||
| ) |
Return the indices of an array corresponding to strictly monotonic decreasing behavior.
arr : numpy.ndarray Input array start : int Starting index (first element if None) end : int Ending index (last element if None)
indices : numpy.ndarray Selected indices
| def src.nifty.multiD_statisticalInefficiency | ( | A_n, | |
B_n = None, |
|||
fast = False, |
|||
mintime = 3, |
|||
warn = True |
|||
| ) |
| def src.nifty.natural_sort | ( | l | ) |
| def src.nifty.onefile | ( | fnm = None, |
|
ext = None, |
|||
err = False |
|||
| ) |
| def src.nifty.orthogonalize | ( | vec1, | |
| vec2 | |||
| ) |
Given two vectors vec1 and vec2, project out the component of vec1 that is along the vec2-direction.
| [in] | vec1 | The projectee (i.e. output is some modified version of vec1) |
| [in] | vec2 | The projector (component subtracted out from vec1 is parallel to this) |
| def src.nifty.pmat2d | ( | mat2d, | |
precision = 1, |
|||
format = "e", |
|||
loglevel = INFO |
|||
| ) |
| def src.nifty.printcool | ( | text, | |
sym = "#", |
|||
bold = False, |
|||
color = 2, |
|||
ansi = None, |
|||
bottom = '-', |
|||
minwidth = 50, |
|||
center = True, |
|||
sym2 = "=" |
|||
| ) |
Cool-looking printout for slick formatting of output.
| [in] | text | The string that the printout is based upon. This function will print out the string, ANSI-colored and enclosed in the symbol for example: ################# ### I am cool ### ################# |
| [in] | sym | The surrounding symbol |
| [in] | bold | Whether to use bold print |
| [in] | color | The ANSI color: 1 red 2 green 3 yellow 4 blue 5 magenta 6 cyan 7 white |
| [in] | bottom | The symbol for the bottom bar |
| [in] | minwidth | The minimum width for the box, if the text is very short then we insert the appropriate number of padding spaces |
Definition at line 321 of file nifty.py.
| def src.nifty.printcool_dictionary | ( | Dict, | |
title = "Dictionary Keys : Values", |
|||
bold = False, |
|||
color = 2, |
|||
keywidth = 25, |
|||
topwidth = 50, |
|||
center = True, |
|||
leftpad = 0 |
|||
| ) |
See documentation for printcool; this is a nice way to print out keys/values in a dictionary.
The keys in the dictionary are sorted before printing out.
| [in] | dict | The dictionary to be printed |
| [in] | title | The title of the printout |
Definition at line 366 of file nifty.py.
| def src.nifty.pvec1d | ( | vec1d, | |
precision = 1, |
|||
format = "e", |
|||
loglevel = INFO |
|||
| ) |
| def src.nifty.queue_up | ( | wq, | |
| command, | |||
| input_files, | |||
| output_files, | |||
tag = None, |
|||
tgt = None, |
|||
verbose = True, |
|||
print_time = 60 |
|||
| ) |
Submit a job to the Work Queue.
| [in] | wq | (Work Queue Object) |
| [in] | command | (string) The command to run on the remote worker. |
| [in] | input_files | (list of files) A list of locations of the input files. |
| [in] | output_files | (list of files) A list of locations of the output files. |
| def src.nifty.queue_up_src_dest | ( | wq, | |
| command, | |||
| input_files, | |||
| output_files, | |||
tag = None, |
|||
tgt = None, |
|||
verbose = True, |
|||
print_time = 60 |
|||
| ) |
Submit a job to the Work Queue.
This function is a bit fancier in that we can explicitly specify where the input files come from, and where the output files go to.
| [in] | wq | (Work Queue Object) |
| [in] | command | (string) The command to run on the remote worker. |
| [in] | input_files | (list of 2-tuples) A list of local and remote locations of the input files. |
| [in] | output_files | (list of 2-tuples) A list of local and remote locations of the output files. |
| def src.nifty.remove_if_exists | ( | fnm | ) |
| def src.nifty.row | ( | vec | ) |
| def src.nifty.statisticalInefficiency | ( | A_n, | |
B_n = None, |
|||
fast = False, |
|||
mintime = 3, |
|||
warn = True |
|||
| ) |
Compute the (cross) statistical inefficiency of (two) timeseries.
Notes The same timeseries can be used for both A_n and B_n to get the autocorrelation statistical inefficiency. The fast method described in Ref [1] is used to compute g.
References [1] J. D. Chodera, W. C. Swope, J. W. Pitera, C. Seok, and K. A. Dill. Use of the weighted histogram analysis method for the analysis of simulated and parallel tempering simulations. JCTC 3(1):26-41, 2007.
Examples
Compute statistical inefficiency of timeseries data with known correlation time.
import timeseries A_n = timeseries.generateCorrelatedTimeseries(N=100000, tau=5.0) g = statisticalInefficiency(A_n, fast=True)
@param[in] A_n (required, numpy array) - A_n[n] is nth value of timeseries A. Length is deduced from vector. @param[in] B_n (optional, numpy array) - B_n[n] is nth value of timeseries B. Length is deduced from vector. If supplied, the cross-correlation of timeseries A and B will be estimated instead of the autocorrelation of timeseries A. @param[in] fast (optional, boolean) - if True, will use faster (but less accurate) method to estimate correlation time, described in Ref. [1] (default: False) @param[in] mintime (optional, int) - minimum amount of correlation function to compute (default: 3) The algorithm terminates after computing the correlation time out to mintime when the correlation function furst goes negative. Note that this time may need to be increased if there is a strong initial negative peak in the correlation function. @return g The estimated statistical inefficiency (equal to 1 + 2 tau, where tau is the correlation time). We enforce g >= 1.0.
| def src.nifty.warn_once | ( | warning, | |
warnhash = None |
|||
| ) |
| def src.nifty.wopen | ( | dest, | |
binary = False |
|||
| ) |
| def src.nifty.wq_wait | ( | wq, | |
wait_time = 10, |
|||
wait_intvl = 10, |
|||
print_time = 60, |
|||
verbose = False |
|||
| ) |
| def src.nifty.wq_wait1 | ( | wq, | |
wait_time = 10, |
|||
wait_intvl = 1, |
|||
print_time = 60, |
|||
verbose = False |
|||
| ) |
| int src.nifty.cm2au = 100 * c_lightspeed * (2*np.pi*hbar) * avogadro / 1000 / au2kj |
| float src.nifty.eqcgmx = au2kj |
| float src.nifty.fqcgmx = -grad_au2gmx |
| float src.nifty.grad_gmx2au = 1.0 / grad_au2gmx |
| src.nifty.handler = RawStreamHandler() |
| float src.nifty.kb = 0.008314462618 |
| src.nifty.rootdir = os.path.dirname(os.path.abspath(__file__)) |
| src.nifty.specific_dct = dict(list(itertools.chain(*[[(j,i[1]) for j in i[0]] for i in specific_lst]))) |
| list src.nifty.specific_lst |
1.8.13