Calculations

Mathematical helpers.

storylines.calc.add(A, B)[source]

Calculate sum of two vectors.

Parameters:
A, Blist of float

Vectors to be added.

Returns:
list of float

Sum of A and B.

storylines.calc.bonds(R1, R2=None, d1=0.0, d2=None, dmin=0.1, dmax=5.0)[source]

Find lines that connect two sets of points.

Parameters:
R1, R2list of tuple

Two (ordered) sets of points.

d1, d2float

Shortening on the two line ends.

dmin, dmaxfloat

Minimum and maximum line length.

Returns:
list of list of tuple

Connecting lines.

storylines.calc.cross(A, B)[source]

Calculate cross product of two vectors.

Parameters:
A, Blist of float

Vectors to be multiplied.

Returns:
list of float

Cross product of A and B.

storylines.calc.distance(A, B)[source]

Calculate distance of two vectors.

Parameters:
A, Blist of float

Vectors.

Returns:
float

Distance of A and B.

storylines.calc.divide(A, b)[source]

Divide vector by scalar.

Parameters:
Alist of float

Vector.

bfloat

Scalar.

Returns:
list of float

A divided by b.

storylines.calc.dot(A, B)[source]

Calculate dot product of two vectors.

Parameters:
A, Blist of float

Vectors to be multiplied.

Returns:
float

Dot product of A and B.

storylines.calc.faces(R, d=0.0, dmin=0.1, dmax=5.0, nc=10)[source]

Find triangular faces, e.g., of tetrahedra of atoms.

Parameters:
Rlist of tuple

(Ordered) set of points.

dfloat

Shortening at the corners, e.g., atomic radius.

dmin, dmaxfloat

Minimum and maximum side length.

ncint

Number of points to trace path around corners.

Returns:
list of list of tuple

Outlines of faces.

storylines.calc.length(A)[source]

Calculate length of vector.

Parameters:
Alist of float

Vector.

Returns:
float

Length of A.

storylines.calc.multiples(lower, upper, divisor=1)[source]

Iterate over all integer multiples of given number on closed interval.

Parameters:
lower, upperfloat

Bounds of closed interval.

divisorfloat

Number the results shall be multiples of.

Yields:
float

Multiple of divisor between lower and upper.

storylines.calc.multiply(A, b)[source]

Multiply vector by scalar.

Parameters:
Alist of float

Vector.

bfloat

Scalar.

Returns:
list of float

A multiplied by b.

storylines.calc.order_of_magnitude(x)[source]

Calculate the decimal order of magnitude.

Parameters:
xfloat

Number of which to calculate the decimal order of magnitude.

Returns:
int

Order of magnitude of x.

storylines.calc.power_of_ten(x)[source]

Calculate the power of ten of the same order of magnitude.

Parameters:
xfloat

Number of which to calculate the power of ten of the same order of magnitude.

Returns:
float

Power of ten of the same order of magnitude as x.

storylines.calc.spring(r1, r2, N=500, k=50, radius=0.1, ends=0.15, xscale=1.0, yscale=1.0)[source]

Draw coil spring in three-dimensional space.

Parameters:
r1, r2list of float

End points.

Nint

Number of path segments.

kfloat

Winding wave vector.

radiusfloat

Radius of spring.

endsfloat

Taper length on both ends.

scalex, scaleyfloat, default 1.0

Scaling factors in transverse directions. If only one of these is zero, the coil becomes a flat wavy line.

Returns:
list of list of float

Coordinates of spring.

storylines.calc.subtract(A, B)[source]

Calculate difference of two vectors.

Parameters:
A, Blist of float

Vectors to be subtracted.

Returns:
list of float

Difference of A and B.

storylines.calc.xround(x, divisor=1)[source]

Round to multiple of given number.

Parameters:
xfloat

Number to round.

divisorfloat

Number the result shall be a multiple of.

Returns:
float

x rounded to the closest multiple of divisor.

storylines.calc.xround_mantissa(x, divisor=1)[source]

Round mantissa to multiple of given number.

The mantissa is the part before the power of ten in scientific notation.

Parameters:
xfloat

Number the mantissa of which to round.

divisorfloat

Number the rounded mantissa shall be a multiple of.

Returns:
float

x with the mantissa rounded to the closest multiple of divisor.