ForceBalance API  1.1
Automated optimization of force fields and empirical potentials
 All Classes Namespaces Files Functions Variables Pages
Classes | Functions | Variables
nifty Namespace Reference

Classes

class  Pickler_LP
 A subclass of the python Pickler that implements pickling of _ElementTree types. More...
 
class  Unpickler_LP
 A subclass of the python Unpickler that implements unpickling of _ElementTree types. More...
 

Functions

def pvec1d
 Printout of a 1-D vector. More...
 
def pmat2d
 Printout of a 2-D matrix. More...
 
def encode
 
def segments
 
def commadash
 
def uncommadash
 
def printcool
 Cool-looking printout for slick formatting of output. More...
 
def printcool_dictionary
 See documentation for printcool; this is a nice way to print out keys/values in a dictionary. More...
 
def isint
 ONLY matches integers! If you have a decimal point? None shall pass! More...
 
def isfloat
 Matches ANY number; it can be a decimal, scientific notation, what have you CAUTION - this will also match an integer. More...
 
def isdecimal
 Matches things with a decimal only; see isint and isfloat. More...
 
def floatornan
 Returns a big number if we encounter NaN. More...
 
def col
 Given any list, array, or matrix, return a 1-column matrix. More...
 
def row
 Given any list, array, or matrix, return a 1-row matrix. More...
 
def flat
 Given any list, array, or matrix, return a single-index array. More...
 
def orthogonalize
 Given two vectors vec1 and vec2, project out the component of vec1 that is along the vec2-direction. More...
 
def invert_svd
 Invert a matrix using singular value decomposition. More...
 
def get_least_squares
 
def statisticalInefficiency
 Compute the (cross) statistical inefficiency of (two) timeseries. More...
 
def lp_dump
 Use this instead of pickle.dump for pickling anything that contains _ElementTree types. More...
 
def lp_load
 Use this instead of pickle.load for unpickling anything that contains _ElementTree types. More...
 
def getWorkQueue
 
def getWQIds
 
def createWorkQueue
 
def destroyWorkQueue
 
def queue_up
 Submit a job to the Work Queue. More...
 
def queue_up_src_dest
 Submit a job to the Work Queue. More...
 
def wq_wait1
 This function waits ten seconds to see if a task in the Work Queue has finished. More...
 
def wq_wait
 This function waits until the work queue is completely empty. More...
 
def GoInto
 
def allsplit
 
def Leave
 
def MissingFileInspection
 
def LinkFile
 
def CopyFile
 
def link_dir_contents
 
def remove_if_exists
 Remove the file if it exists (doesn't return an error). More...
 
def which
 
def warn_press_key
 
def warn_once
 Prints a warning but will only do so once in a given run. More...
 
def concurrent_map
 Similar to the bultin function map(). More...
 
def multiopen
 This function be given any of several variable types (single file name, file object, or list of lines, or a list of the above) and give a list of files: More...
 

Variables

tuple logger = getLogger(__name__)
 
float kb = 0.0083144100163
 Boltzmann constant. More...
 
float eqcgmx = 2625.5002
 Q-Chem to GMX unit conversion for energy. More...
 
float fqcgmx = -49621.9
 Q-Chem to GMX unit conversion for force. More...
 
float bohrang = 0.529177249
 One bohr equals this many angstroms. More...
 
string XMLFILE = 'x'
 Pickle uses 'flags' to pickle and unpickle different variable types. More...
 
 WORK_QUEUE = None
 
tuple WQIDS = defaultdict(list)
 
list specific_lst
 
tuple specific_dct = dict(list(itertools.chain(*[[(j,i[1]) for j in i[0]] for i in specific_lst])))
 

Function Documentation

def nifty.allsplit (   Dir)

Definition at line 745 of file nifty.py.

Here is the call graph for this function:

def nifty.col (   vec)

Given any list, array, or matrix, return a 1-column matrix.

Input: vec = The input vector that is to be made into a column

Output: A column matrix

Definition at line 271 of file nifty.py.

Here is the call graph for this function:

def nifty.commadash (   l)

Definition at line 82 of file nifty.py.

Here is the call graph for this function:

def nifty.concurrent_map (   func,
  data 
)

Similar to the bultin function map().

But spawn a thread for each argument and apply func concurrently.

Note: unlike map(), we cannot take an iterable argument. data should be an indexable sequence.

Definition at line 950 of file nifty.py.

def nifty.CopyFile (   src,
  dest 
)

Definition at line 793 of file nifty.py.

Here is the call graph for this function:

def nifty.createWorkQueue (   wq_port,
  debug = True 
)

Definition at line 580 of file nifty.py.

def nifty.destroyWorkQueue ( )

Definition at line 590 of file nifty.py.

Here is the call graph for this function:

def nifty.encode (   l)

Definition at line 73 of file nifty.py.

Here is the call graph for this function:

def nifty.flat (   vec)

Given any list, array, or matrix, return a single-index array.

Parameters
[in]vecThe data to be flattened
Returns
answer The flattened data

Definition at line 290 of file nifty.py.

Here is the call graph for this function:

def nifty.floatornan (   word)

Returns a big number if we encounter NaN.

 @param[in] word The string to be converted
 @return answer The string converted to a float; if not a float, return 1e10
Todo:
I could use suggestions for making this better.

Definition at line 253 of file nifty.py.

Here is the call graph for this function:

def nifty.get_least_squares (   x,
  y,
  w = None,
  thresh = 1e-12 
)
1  __ __
2 | |
3 | 1 (x0) (x0)^2 (x0)^3 |
4 | 1 (x1) (x1)^2 (x1)^3 |
5 | 1 (x2) (x2)^2 (x2)^3 |
6 | 1 (x3) (x3)^2 (x3)^3 |
7 | 1 (x4) (x4)^2 (x4)^3 |
8 |__ __|
Parameters
[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]BetaThe least-squares coefficients
[out]HatThe hat matrix that takes linear combinations of data y-values to give fitted y-values (weights)
[out]yfitThe fitted y-values
[out]MPPIThe 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 358 of file nifty.py.

Here is the call graph for this function:

def nifty.getWorkQueue ( )

Definition at line 572 of file nifty.py.

def nifty.getWQIds ( )

Definition at line 576 of file nifty.py.

Here is the call graph for this function:

def nifty.GoInto (   Dir)

Definition at line 737 of file nifty.py.

def nifty.invert_svd (   X,
  thresh = 1e-12 
)

Invert a matrix using singular value decomposition.

Parameters
[in]XThe matrix to be inverted
[in]threshThe SVD threshold; eigenvalues below this are not inverted but set to zero
Returns
Xt The inverted matrix

Definition at line 317 of file nifty.py.

Here is the call graph for this function:

def nifty.isdecimal (   word)

Matches things with a decimal only; see isint and isfloat.

Parameters
[in]wordString (for instance, '123', '153.0', '2.', '-354')
Returns
answer Boolean which specifies whether the string is a number with a decimal point

Definition at line 243 of file nifty.py.

Here is the call graph for this function:

def nifty.isfloat (   word)

Matches ANY number; it can be a decimal, scientific notation, what have you CAUTION - this will also match an integer.

Parameters
[in]wordString (for instance, '123', '153.0', '2.', '-354')
Returns
answer Boolean which specifies whether the string is any number

Definition at line 233 of file nifty.py.

Here is the call graph for this function:

def nifty.isint (   word)

ONLY matches integers! If you have a decimal point? None shall pass!

Parameters
[in]wordString (for instance, '123', '153.0', '2.', '-354')
Returns
answer Boolean which specifies whether the string is an integer (only +/- sign followed by digits)

Definition at line 222 of file nifty.py.

Here is the call graph for this function:

def nifty.Leave (   Dir)

Definition at line 751 of file nifty.py.

def nifty.link_dir_contents (   abssrcdir,
  absdestdir 
)

Definition at line 803 of file nifty.py.

def nifty.LinkFile (   src,
  dest 
)

Definition at line 782 of file nifty.py.

Here is the call graph for this function:

def nifty.lp_dump (   obj,
  file,
  protocol = None 
)

Use this instead of pickle.dump for pickling anything that contains _ElementTree types.

Definition at line 550 of file nifty.py.

Here is the call graph for this function:

def nifty.lp_load (   file)

Use this instead of pickle.load for unpickling anything that contains _ElementTree types.

Definition at line 555 of file nifty.py.

Here is the call graph for this function:

def nifty.MissingFileInspection (   fnm)

Definition at line 772 of file nifty.py.

Here is the call graph for this function:

def nifty.multiopen (   arg)

This function be given any of several variable types (single file name, file object, or list of lines, or a list of the above) and give a list of files:

[file1, file2, file3 ... ]

each of which can then be iterated over:

[[file1_line1, file1_line2 ... ], [file2_line1, file2_line2 ... ]]

Definition at line 980 of file nifty.py.

def nifty.orthogonalize (   vec1,
  vec2 
)

Given two vectors vec1 and vec2, project out the component of vec1 that is along the vec2-direction.

Parameters
[in]vec1The projectee (i.e. output is some modified version of vec1)
[in]vec2The projector (component subtracted out from vec1 is parallel to this)
Returns
answer A copy of vec1 but with the vec2-component projected out.

Definition at line 304 of file nifty.py.

def nifty.pmat2d (   mat2d,
  precision = 1,
  loglevel = INFO 
)

Printout of a 2-D matrix.

Parameters
[in]mat2da 2-D matrix

Definition at line 66 of file nifty.py.

Here is the call graph for this function:

def nifty.printcool (   text,
  sym = "#",
  bold = False,
  color = 2,
  ansi = None,
  bottom = '-',
  minwidth = 50,
  center = True 
)

Cool-looking printout for slick formatting of output.

Parameters
[in]textThe 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]symThe surrounding symbol
[in]boldWhether to use bold print
[in]colorThe ANSI color:
1 red
2 green
3 yellow
4 blue
5 magenta
6 cyan
7 white
[in]bottomThe symbol for the bottom bar
[in]minwidthThe minimum width for the box, if the text is very short then we insert the appropriate number of padding spaces
Returns
bar The bottom bar is returned for the user to print later, e.g. to mark off a 'section'

Definition at line 155 of file nifty.py.

Here is the call graph for this function:

def nifty.printcool_dictionary (   Dict,
  title = "General options",
  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.

Parameters
[in]dictThe dictionary to be printed
[in]titleThe title of the printout

Definition at line 198 of file nifty.py.

Here is the call graph for this function:

def nifty.pvec1d (   vec1d,
  precision = 1,
  loglevel = INFO 
)

Printout of a 1-D vector.

Parameters
[in]vec1da 1-D vector

Definition at line 55 of file nifty.py.

Here is the call graph for this function:

def nifty.queue_up (   wq,
  command,
  input_files,
  output_files,
  tgt = None,
  verbose = True 
)

Submit a job to the Work Queue.

Parameters
[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.

Definition at line 605 of file nifty.py.

Here is the call graph for this function:

def nifty.queue_up_src_dest (   wq,
  command,
  input_files,
  output_files,
  tgt = None,
  verbose = True 
)

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.

Parameters
[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.

Definition at line 637 of file nifty.py.

def nifty.remove_if_exists (   fnm)

Remove the file if it exists (doesn't return an error).

Definition at line 814 of file nifty.py.

def nifty.row (   vec)

Given any list, array, or matrix, return a 1-row matrix.

Parameters
[in]vecThe input vector that is to be made into a row
Returns
answer A row matrix

Definition at line 281 of file nifty.py.

Here is the call graph for this function:

def nifty.segments (   e)

Definition at line 76 of file nifty.py.

Here is the call graph for this function:

def 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.

Definition at line 434 of file nifty.py.

def nifty.uncommadash (   s)

Definition at line 92 of file nifty.py.

Here is the call graph for this function:

def nifty.warn_once (   warning,
  warnhash = None 
)

Prints a warning but will only do so once in a given run.

Definition at line 926 of file nifty.py.

Here is the call graph for this function:

def nifty.warn_press_key (   warning,
  timeout = 10 
)

Definition at line 911 of file nifty.py.

Here is the call graph for this function:

def nifty.which (   fnm)

Definition at line 818 of file nifty.py.

Here is the call graph for this function:

def nifty.wq_wait (   wq,
  wait_time = 10,
  wait_intvl = 10,
  print_time = 60,
  verbose = False 
)

This function waits until the work queue is completely empty.

Definition at line 730 of file nifty.py.

Here is the call graph for this function:

def nifty.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.

Definition at line 658 of file nifty.py.

Here is the call graph for this function:

Variable Documentation

float nifty.bohrang = 0.529177249

One bohr equals this many angstroms.

Definition at line 45 of file nifty.py.

float nifty.eqcgmx = 2625.5002

Q-Chem to GMX unit conversion for energy.

Definition at line 41 of file nifty.py.

float nifty.fqcgmx = -49621.9

Q-Chem to GMX unit conversion for force.

Definition at line 43 of file nifty.py.

float nifty.kb = 0.0083144100163

Boltzmann constant.

Definition at line 39 of file nifty.py.

tuple nifty.logger = getLogger(__name__)

Definition at line 34 of file nifty.py.

tuple nifty.specific_dct = dict(list(itertools.chain(*[[(j,i[1]) for j in i[0]] for i in specific_lst])))

Definition at line 770 of file nifty.py.

list nifty.specific_lst
Initial value:
1 = [(['mdrun','grompp','trjconv','g_energy','g_traj'], "Make sure to install GROMACS and add it to your path (or set the gmxpath option)"),
2  (['force.mdin', 'stage.leap'], "This file is needed for setting up AMBER force matching targets"),
3  (['conf.pdb', 'mono.pdb'], "This file is needed for setting up OpenMM condensed phase property targets"),
4  (['liquid.xyz', 'liquid.key', 'mono.xyz', 'mono.key'], "This file is needed for setting up OpenMM condensed phase property targets"),
5  (['dynamic', 'analyze', 'minimize', 'testgrad', 'vibrate', 'optimize', 'polarize', 'superpose'], "Make sure to install TINKER and add it to your path (or set the tinkerpath option)"),
6  (['runcuda.sh', 'npt.py', 'npt_tinker.py'], "This file belongs in the ForceBalance source directory, not sure why it is missing"),
7  (['input.xyz'], "This file is needed for TINKER molecular property targets"),
8  (['.*key$', '.*xyz$'], "I am guessing this file is probably needed by TINKER"),
9  (['.*gro$', '.*top$', '.*itp$', '.*mdp$', '.*ndx$'], "I am guessing this file is probably needed by GROMACS")
10  ]

Definition at line 758 of file nifty.py.

nifty.WORK_QUEUE = None

Definition at line 567 of file nifty.py.

tuple nifty.WQIDS = defaultdict(list)

Definition at line 570 of file nifty.py.

string nifty.XMLFILE = 'x'

Pickle uses 'flags' to pickle and unpickle different variable types.

Here we use the letter 'x' to signify that the variable type is an XML file.

Definition at line 496 of file nifty.py.