pymchelper.flair.common package#

Submodules#

pymchelper.flair.common.bmath module#

pymchelper.flair.common.bmath.Cmp0(x)[source]#
class pymchelper.flair.common.bmath.DefaultDict(default=None)[source]#

Bases: dict

class pymchelper.flair.common.bmath.Matrix(rows=4, cols=-1, type=0)[source]#

Bases: list

Matrix 4x4 used for vector transformations

O = [[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]]#
T()[source]#

@return transpose matrix

U = [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]]#
append(col)[source]#

Append object to the end of the list.

clone()[source]#

Clone matrix

det(eps=1e-15)[source]#

determinant of square matrix using Gauss method

determinant(eps=1e-15)#

determinant of square matrix using Gauss method

static diagonal(lst)[source]#
static eulerRotation(rx, ry, rz)[source]#
getEulerRotation()[source]#
inv()[source]#

Inverse matrix in place

inverse()#

Inverse matrix in place

make(X, Y, Z=None, T=None)[source]#

Create a transformation matrix from 3 normalized vectors

multNoTranslation(B)[source]#

Multiply matrix with a vector ignoring the translation part

static rotX(angle)[source]#

m = Matrix.rotX(angle) - Return a rotation matrix around X

static rotY(angle)[source]#

m = Matrix.rotY(angle) - Return a rotation matrix arround Y

static rotZ(angle)[source]#

m = Matrix.rotZ(angle) - Return a rotation matrix arround Z

rotate(angle, axis)[source]#

Add rotation elements to the matrix around one axis Axis X=0, Y=1, Z=2, or an arbitrary one given by vector axis

static scale(sx, sy=None, sz=None)[source]#

m = Matrix.scale(scale|vector) @return a scaling matrix

trace()[source]#

Return trace of matrix (sum of diagonal elements)

static translate(x, y=0.0, z=0.0)[source]#

m = Matrix.translate(x,y,z|vector) @return a translation matrix

transpose()#

@return transpose matrix

unary()[source]#

Unary matrix

writeOctave(filename, name)[source]#

Write an octave matrix file

zero()[source]#

Zero matrix

class pymchelper.flair.common.bmath.Quaternion(a, b=None, c=None, d=None)[source]#

Bases: list

matrix()[source]#

return rotation matrix

norm()[source]#

normalize quaternion

normalize()#

normalize quaternion

vector()[source]#

return vector of quaternion

class pymchelper.flair.common.bmath.Vector(x=3, *args)[source]#

Bases: list

Vector class

O = [0.0, 0.0, 0.0]#
X = [1.0, 0.0, 0.0]#
Y = [0.0, 1.0, 0.0]#
Z = [0.0, 0.0, 1.0]#
arg()[source]#

return vector angle

clone()[source]#

Clone vector

cosTheta()[source]#
cross(v)[source]#

Cross product of 2 vectors

direction(zero=1e-15)[source]#

return containing the direction if normalized with any of the axis

dot(v)[source]#

Dot product of 2 vectors

eq(v, acc=1e-15)[source]#

Test for equality with vector v within accuracy

length()[source]#

Return length of vector

length2()[source]#

Return length squared of vector

norm()[source]#

Normalize vector and return length

normalize()#

Normalize vector and return length

orthogonal()[source]#

return a vector orthogonal to self

perp()[source]#
perp2()[source]#
phi()[source]#
set(x, y, z=None)[source]#

Set vector

setPolar(ma, ph, th)[source]#
theta()[source]#
unit()[source]#

return a unit vector

x()[source]#
y()[source]#
z()[source]#
class pymchelper.flair.common.bmath.ZeroDict[source]#

Bases: DefaultDict

class pymchelper.flair.common.bmath.ZeroIntDict[source]#

Bases: DefaultDict

pymchelper.flair.common.bmath.cubic(a, b, c, d=None, eps=1e-15)[source]#
pymchelper.flair.common.bmath.d2s(ang, fmt='')[source]#
pymchelper.flair.common.bmath.dms(d, m, s)[source]#
pymchelper.flair.common.bmath.eigenvalues(M, eps=1e-15, check=False)[source]#

Return eigen values and eigen vectors of a symmetric matrix

pymchelper.flair.common.bmath.fitPlane(xyz)[source]#
pymchelper.flair.common.bmath.format_number(number, length=10, useExp=False, useD=False)[source]#

Format a number to fit in the minimum space given by length

pymchelper.flair.common.bmath.frange(start, stop, step)[source]#

range(start,stop,step) for floating point numbers

pymchelper.flair.common.bmath.gauss(A, B)[source]#

Solve A*X = B using the Gauss elimination method

pymchelper.flair.common.bmath.goldenSectionSearch(func, ax, bx, cx, x, d=1, eps=1e-15)[source]#
pymchelper.flair.common.bmath.int2roman(num)[source]#

Convert an integer to Roman numeral

pymchelper.flair.common.bmath.limit(min_, num, max_)[source]#

limit a number within a specific range :param min_: :param num: :param max_: :return:

pymchelper.flair.common.bmath.linear(X, Y)[source]#

Solve linear regression y = ax + b @return a,b,r

pymchelper.flair.common.bmath.polar(x, y, deg=False)[source]#
Convert from rectangular (x,y) to polar (r,w)

r = sqrt(x^2 + y^2) w = arctan(y/x) = [-pi,pi] = [-180,180]

pymchelper.flair.common.bmath.polyderiv(a)[source]#
p’(x) = polyderiv(a)

= b[0] + b[1]x + b[2]x^2 +…+ b[n-2]x^{n-2} + b[n-1]x^{n-1}

where b[i] = (i+1)a[i+1]

pymchelper.flair.common.bmath.polyeval(a, x)[source]#
p(x) = polyeval(a, x)

= a[0] + a[1]x + a[2]x^2 +…+ a[n-1]x^{n-1} + a[n]x^n = a[0] + x(a[1] + x(a[2] +…+ x(a[n-1] + a[n]x)…)

pymchelper.flair.common.bmath.polyreduce(a, root)[source]#

Given x = r is a root of n’th degree polynomial p(x) = (x-r)q(x), divide p(x) by linear factor (x-r) using the same algorithm as polynomial evaluation. Then, return the (n-1)’th degree quotient q(x) = polyreduce(a, r)

= c[0] + c[1]x + c[2]x^2 +…+ c[n-2]x^{n-2} + c[n-1]x^{n-1}

pymchelper.flair.common.bmath.quadratic(b, c, eps=1e-15)[source]#
pymchelper.flair.common.bmath.random3D()[source]#
pymchelper.flair.common.bmath.rect(r, w, deg=False)[source]#
Convert from polar (r,w) to rectangular (x,y)

x = r cos(w) y = r sin(w)

pymchelper.flair.common.bmath.rndColor(x)[source]#
pymchelper.flair.common.bmath.roman2int(roman)[source]#

convert a roman string to integer

pymchelper.flair.common.bmath.solveOverDetermined(A, B, W=None)[source]#
Solve the overdetermined linear system defined by the matrices A,B

such as A*X = B

Optionally a weight can be specified

pymchelper.flair.common.bmath.xcombinations(items, n)[source]#
pymchelper.flair.common.bmath.xpermutations(items)[source]#
pymchelper.flair.common.bmath.xselections(items, n)[source]#
pymchelper.flair.common.bmath.xuniqueCombinations(items, n)[source]#

pymchelper.flair.common.csg module#

exception pymchelper.flair.common.csg.CSGException[source]#

Bases: Exception

pymchelper.flair.common.csg.check(expr)[source]#

check depth of an rpn expression

pymchelper.flair.common.csg.exp2rpn(expr)[source]#

Convert the FLUKA Boolean expression to Reverse Polish Notation (RPN) Since the normalization routine does not accept the +/- as signs to objects, the routine is converting the leading - to @- (Universe minus) where the special symbol @ is treated as the universe. Furthermore the leading + is ignored as well as the leading | which is accepted by fluka.

WARNING: No check is done for the correctness of the expression apart

from the parenthesis nesting

ie.

A+B -> A B +

(A+B)|C -> A B + C | (A|B)|C+D|E -> A B | C D + | E | -A -> @ A - -(-A) -> @ @ A - -

The routine is using the same array for returning the Reverse Polish expression, since the format is more compact. This is generally true apart one case -A -> @ A -

Priorities are treated as:

Operator Priority In Out ——– ——– — —

lower 1 2
  • high 3 4

  • high 3 4

( higher 99 0 ) higher 0 99 object highest 101 100

Algorithm

Consider the expression as a train moving on a railroad with a T-shape, where each token is one wagon

<- (A|B)|C+D

————. .———— RPN-End | / Exp-End


S| t| a| c| k|

Each wagon to move from the Exp-End to the RPN-End it has to make a stop first in the Stack-End. Before entering in the stack, the priority-IN will be checked against the objects in the stack. All top-most objects currently present in the stack with higher priority-OUT will be transfered from the stack to the RPN-End. Apart from the opening parenthesis ( which is discarded.

Example: (1) A+B|C (1) (2) A +B|C (2) (3) A B|C (3) (4) A |C (4) (5) A B + C (5) (6) A B + C (7) A B + C |

————. .———— RPN-End | / Exp-End


S| t| a| c| B C k| A + + | | |

1 2 3 4 5 6 7

Parameters:

expr

Returns:

pymchelper.flair.common.csg.optZone(plus, minus)[source]#

Optimize a product, by removing the universe @, duplicated terms like A+A, A-A, -A-A, and finally calling the geometrical optimizations and sorting by name the primitives in both the plus and minus terms.

The product is described by 2 arrays the PLUS,NPLUS and MINUS,NMINUS with all the plus and minus terms of the product

WARNING: It doesn’t delete the term from the arrays but changes the name to space. :param plus: :param minus: :return:

pymchelper.flair.common.csg.rmDoubles(zones)[source]#

Remove duplicates of products A+B|A+B|C+D -> A+B|C+D :param zones: :return:

pymchelper.flair.common.csg.rpn2exp(rpn)[source]#

Convert a NORMALIZED Reverse Polish notation to a standard expression WARNING: The routine expects an expression where for each UNION operator the right-sub-expression is a product while the left can be UNION or a product :param rpn: :return:

pymchelper.flair.common.csg.rpnorm(expr)[source]#

Normalize a CG expression given in Reverse Polish Notation. Normalized CG expression is an expression given as sum (Boolean OR) of products (Boolean intersection or subtraction). The normalization (expansion of parenthesis and operator priorities) should be performed by recursively calling the RPNRULE subroutine. Since Fortran-77 doesn’t have recursion, call the RPNRULE for every operator starting from the right-most one, until no rule is found. :param expr: :return:

pymchelper.flair.common.csg.split(expr)[source]#

Break products into lists :param expr: :return:

pymchelper.flair.common.csg.splitZones(expr)[source]#

split a tokenized expression into zones

pymchelper.flair.common.csg.toString(expr)[source]#

return a string version of a tokenize expression

pymchelper.flair.common.csg.tokenize(expr)[source]#

return a list of expression tokens

pymchelper.flair.common.fortran module#

pymchelper.flair.common.fortran.read(f)[source]#

Read a fortran structure from a binary file :param f: file to read from :return: data, None for EOF

pymchelper.flair.common.fortran.skip(f)[source]#

Skip a fortran block from a binary file :param f: file to read from :return: size, None for EOF

pymchelper.flair.common.fortran.write(f, d)[source]#

Write a block of data (string) to file as a fortran block :param f: file to write to :param d: data to write :return: output of last write statement

pymchelper.flair.common.log module#

pymchelper.flair.common.log.null()[source]#
pymchelper.flair.common.log.say(*kw)[source]#
pymchelper.flair.common.log.set_log(log)[source]#

pymchelper.flair.common.rexx module#

pymchelper.flair.common.rexx.abbrev(information, info, length=0)[source]#

return true if the info is an abbreviation of information with minimum length l

pymchelper.flair.common.rexx.center(s, length, pad=' ')[source]#
pymchelper.flair.common.rexx.datatype(str, check='N')[source]#

rexx datatype function

pymchelper.flair.common.rexx.insert(new, target, n, pad=' ')[source]#

insert new string to target as position n padded with pad characters

pymchelper.flair.common.rexx.left(str, length, pad=' ')[source]#

return left of string str of length padded with pad chars

pymchelper.flair.common.rexx.reverse(str)[source]#

reverse string

pymchelper.flair.common.rexx.translate(str, tableo=None, tablei=None, pad=' ')[source]#

translate string

pymchelper.flair.common.rexx.verify(str, ref, match=0, start=0)[source]#

return the index of the first character in string that is not also in reference. if “Match” is given, then return the result index of the first character in string that is in reference

pymchelper.flair.common.rexx.xrange_string(start, stop)[source]#

Module contents#