code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
r12, r22 = self.z1*self.z1, self.z2*self.z2 r = np.sqrt(r12 + r22) return r
def mod_c(self)
Complex modulus
4.176311
3.548812
1.17682
m = len(x) _assert(n < m, 'len(x) must be larger than n') weights = np.zeros((m, n + 1)) _fd_weights_all(weights, x, x0, n) return weights.T
def fd_weights_all(x, x0=0, n=1)
Return finite difference weights for derivatives of all orders up to n. Parameters ---------- x : vector, length m x-coordinates for grid points x0 : scalar location where approximations are to be accurate n : scalar integer highest derivative that we want to find weights fo...
3.701678
4.638862
0.797971
num_x = len(x) _assert(n < num_x, 'len(x) must be larger than n') _assert(num_x == len(fx), 'len(x) must be equal len(fx)') du = np.zeros_like(fx) mm = n // 2 + m size = 2 * mm + 2 # stencil size at boundary # 2 * mm boundary points for i in range(mm): du[i] = np.dot(fd_w...
def fd_derivative(fx, x, n=1, m=2)
Return the n'th derivative for all points using Finite Difference method. Parameters ---------- fx : vector function values which are evaluated on x i.e. fx[i] = f(x[i]) x : vector abscissas on which fx is evaluated. The x values can be arbitrarily spaced but must be distinct a...
2.752019
2.750626
1.000506
check_points = (-0.4 + 0.3j, 0.7 + 0.2j, 0.02 - 0.06j) diffs = [] ftests = [] for check_point in check_points: rtest = r * check_point ztest = z + rtest ftest = f(ztest) # Evaluate powerseries: comp = np.sum(bn * np.power(check_point, mvec)) ftests.ap...
def _poor_convergence(z, r, f, bn, mvec)
Test for poor convergence based on three function evaluations. This test evaluates the function at the three points and returns false if the relative error is greater than 1e-3.
3.601862
3.52176
1.022745
_assert(n < 193, 'Number of derivatives too large. Must be less than 193') correction = np.array([0, 0, 1, 3, 4, 7])[_get_logn(n)] log2n = _get_logn(n - correction) m = 2 ** (log2n + 3) return m
def _num_taylor_coefficients(n)
Return number of taylor coefficients Parameters ---------- n : scalar integer Wanted number of taylor coefficients Returns ------- m : scalar integer Number of taylor coefficients calculated 8 if n <= 6 16 if 6 < n <= 12 32 if 12 < n <= 2...
5.777588
5.500472
1.05038
if c is None: c = richardson_parameter(vals, k) return vals[k] - (vals[k] - vals[k - 1]) / c
def richardson(vals, k, c=None)
Richardson extrapolation with parameter estimation
3.589638
3.471691
1.033974
return Taylor(fun, n=n, r=r, num_extrap=num_extrap, step_ratio=step_ratio, **kwds)(z0)
def taylor(fun, z0=0, n=1, r=0.0061, num_extrap=3, step_ratio=1.6, **kwds)
Return Taylor coefficients of complex analytic function using FFT Parameters ---------- fun : callable function to differentiate z0 : real or complex scalar at which to evaluate the derivatives n : scalar integer, default 1 Number of taylor coefficents to compute. Maximum number is ...
2.167357
3.891861
0.556895
result = taylor(fun, z0, n=n, **kwds) # convert taylor series --> actual derivatives. m = _num_taylor_coefficients(n) fact = factorial(np.arange(m)) if kwds.get('full_output'): coefs, info_ = result info = _INFO(info_.error_estimate * fact, *info_[1:]) return coefs * fac...
def derivative(fun, z0, n=1, **kwds)
Calculate n-th derivative of complex analytic function using FFT Parameters ---------- fun : callable function to differentiate z0 : real or complex scalar at which to evaluate the derivatives n : scalar integer, default 1 Number of derivatives to compute where 0 represents the valu...
7.41344
7.74562
0.957114
reverse = mo.DECSCNM in self.mode return Char(data=" ", fg="default", bg="default", reverse=reverse)
def default_char(self)
An empty character with default foreground and background colors.
34.538921
23.646709
1.460623
def render(line): is_wide_char = False for x in range(self.columns): if is_wide_char: # Skip stub is_wide_char = False continue char = line[x].data assert sum(map(wcwidth, char[1:])) == 0 ...
def display(self)
A :func:`list` of screen lines as unicode strings.
6.083933
5.252027
1.158397
self.dirty.update(range(self.lines)) self.buffer.clear() self.margins = None self.mode = set([mo.DECAWM, mo.DECTCEM]) self.title = "" self.icon_name = "" self.charset = 0 self.g0_charset = cs.LAT1_MAP self.g1_charset = cs.VT100_MAP ...
def reset(self)
Reset the terminal to its initial state. * Scrolling margins are reset to screen boundaries. * Cursor is moved to home location -- ``(0, 0)`` and its attributes are set to defaults (see :attr:`default_char`). * Screen is cleared -- each character is reset to :attr:`default_c...
10.379145
8.436747
1.230231
lines = lines or self.lines columns = columns or self.columns if lines == self.lines and columns == self.columns: return # No changes. self.dirty.update(range(lines)) if lines < self.lines: self.save_cursor() self.cursor_position(0...
def resize(self, lines=None, columns=None)
Resize the screen to the given size. If the requested screen size has more lines than the existing screen, lines will be added at the bottom. If the requested size has less lines than the existing screen lines will be clipped at the top of the screen. Similarly, if the existing ...
2.990275
3.456776
0.865047
# XXX 0 corresponds to the CSI with no parameters. if (top is None or top == 0) and bottom is None: self.margins = None return margins = self.margins or Margins(0, self.lines - 1) # Arguments are 1-based, while :attr:`margins` are zero # based -...
def set_margins(self, top=None, bottom=None)
Select top and bottom margins for the scrolling region. :param int top: the smallest line number that is scrolled. :param int bottom: the biggest line number that is scrolled.
5.377151
5.206276
1.032821
# Private mode codes are shifted, to be distingiushed from non # private ones. if kwargs.get("private"): modes = [mode << 5 for mode in modes] if mo.DECSCNM in modes: self.dirty.update(range(self.lines)) self.mode.update(modes) #...
def set_mode(self, *modes, **kwargs)
Set (enable) a given list of modes. :param list modes: modes to set, where each mode is a constant from :mod:`pyte.modes`.
6.43054
6.472188
0.993565
if code in cs.MAPS: if mode == "(": self.g0_charset = cs.MAPS[code] elif mode == ")": self.g1_charset = cs.MAPS[code]
def define_charset(self, code, mode)
Define ``G0`` or ``G1`` charset. :param str code: character set code, should be a character from ``"B0UK"``, otherwise ignored. :param str mode: if ``"("`` ``G0`` charset is defined, if ``")"`` -- we operate on ``G1``. .. warning:: User-defined...
5.104568
3.831189
1.332372
data = data.translate( self.g1_charset if self.charset else self.g0_charset) for char in data: char_width = wcwidth(char) # If this was the last column in a line and auto wrap mode is # enabled, move the cursor to the beginning of the next line,...
def draw(self, data)
Display decoded characters at the current cursor position and advances the cursor if :data:`~pyte.modes.DECAWM` is set. :param str data: text to display. .. versionchanged:: 0.5.0 Character width is taken into account. Specifically, zero-width and unprintable characters ...
3.704601
3.430418
1.079927
top, bottom = self.margins or Margins(0, self.lines - 1) if self.cursor.y == bottom: # TODO: mark only the lines within margins? self.dirty.update(range(self.lines)) for y in range(top, bottom): self.buffer[y] = self.buffer[y + 1] ...
def index(self)
Move the cursor down one line in the same column. If the cursor is at the last line, create a new line at the bottom.
6.468721
5.209255
1.241775
top, bottom = self.margins or Margins(0, self.lines - 1) if self.cursor.y == top: # TODO: mark only the lines within margins? self.dirty.update(range(self.lines)) for y in range(bottom, top, -1): self.buffer[y] = self.buffer[y - 1] ...
def reverse_index(self)
Move the cursor up one line in the same column. If the cursor is at the first line, create a new line at the top.
5.900881
4.891219
1.206423
self.index() if mo.LNM in self.mode: self.carriage_return()
def linefeed(self)
Perform an index and, if :data:`~pyte.modes.LNM` is set, a carriage return.
33.586933
13.390537
2.508259
for stop in sorted(self.tabstops): if self.cursor.x < stop: column = stop break else: column = self.columns - 1 self.cursor.x = column
def tab(self)
Move to the next tab space, or the end of the screen if there aren't anymore left.
6.031346
4.932523
1.222771
self.savepoints.append(Savepoint(copy.copy(self.cursor), self.g0_charset, self.g1_charset, self.charset, mo.DECOM in self.mode, ...
def save_cursor(self)
Push the current cursor position onto the stack.
11.83103
10.166073
1.163776
if self.savepoints: savepoint = self.savepoints.pop() self.g0_charset = savepoint.g0_charset self.g1_charset = savepoint.g1_charset self.charset = savepoint.charset if savepoint.origin: self.set_mode(mo.DECOM) if ...
def restore_cursor(self)
Set the current cursor position to whatever cursor is on top of the stack.
5.894153
5.673369
1.038916
count = count or 1 top, bottom = self.margins or Margins(0, self.lines - 1) # If cursor is outside scrolling margins it -- do nothin'. if top <= self.cursor.y <= bottom: self.dirty.update(range(self.cursor.y, self.lines)) for y in range(bottom, self.curs...
def insert_lines(self, count=None)
Insert the indicated # of lines at line with cursor. Lines displayed **at** and below the cursor move down. Lines moved past the bottom margin are lost. :param count: number of lines to insert.
5.177877
5.434926
0.952704
self.dirty.add(self.cursor.y) count = count or 1 line = self.buffer[self.cursor.y] for x in range(self.columns, self.cursor.x - 1, -1): if x + count <= self.columns: line[x + count] = line[x] line.pop(x, None)
def insert_characters(self, count=None)
Insert the indicated # of blank characters at the cursor position. The cursor does not move and remains at the beginning of the inserted blank characters. Data on the line is shifted forward. :param int count: number of characters to insert.
4.017681
4.351581
0.923269
self.dirty.add(self.cursor.y) count = count or 1 line = self.buffer[self.cursor.y] for x in range(self.cursor.x, min(self.cursor.x + count, self.columns)): line[x] = self.cursor.attrs
def erase_characters(self, count=None)
Erase the indicated # of characters, starting with the character at cursor position. Character attributes are set cursor attributes. The cursor remains in the same position. :param int count: number of characters to erase. .. note:: Using cursor attributes for character att...
3.929976
4.358742
0.901631
self.dirty.add(self.cursor.y) if how == 0: interval = range(self.cursor.x, self.columns) elif how == 1: interval = range(self.cursor.x + 1) elif how == 2: interval = range(self.columns) line = self.buffer[self.cursor.y] for x ...
def erase_in_line(self, how=0, private=False)
Erase a line in a specific way. Character attributes are set to cursor attributes. :param int how: defines the way the line should be erased in: * ``0`` -- Erases from cursor to end of line, including cursor position. * ``1`` -- Erases from beginning of line to c...
2.84769
2.903975
0.980618
if how == 0: interval = range(self.cursor.y + 1, self.lines) elif how == 1: interval = range(self.cursor.y) elif how == 2 or how == 3: interval = range(self.lines) self.dirty.update(interval) for y in interval: line = self...
def erase_in_display(self, how=0, *args, **kwargs)
Erases display in a specific way. Character attributes are set to cursor attributes. :param int how: defines the way the line should be erased in: * ``0`` -- Erases from cursor to end of screen, including cursor position. * ``1`` -- Erases from beginning of scree...
3.182497
3.185037
0.999203
if how == 0: # Clears a horizontal tab stop at cursor position, if it's # present, or silently fails if otherwise. self.tabstops.discard(self.cursor.x) elif how == 3: self.tabstops = set()
def clear_tab_stop(self, how=0)
Clear a horizontal tab stop. :param int how: defines a way the tab stop should be cleared: * ``0`` or nothing -- Clears a horizontal tab stop at cursor position. * ``3`` -- Clears all horizontal tab stops.
7.55569
5.1714
1.461053
self.cursor.x = min(max(0, self.cursor.x), self.columns - 1)
def ensure_hbounds(self)
Ensure the cursor is within horizontal screen bounds.
6.260522
3.110991
2.012388
if (use_margins or mo.DECOM in self.mode) and self.margins is not None: top, bottom = self.margins else: top, bottom = 0, self.lines - 1 self.cursor.y = min(max(top, self.cursor.y), bottom)
def ensure_vbounds(self, use_margins=None)
Ensure the cursor is within vertical screen bounds. :param bool use_margins: when ``True`` or when :data:`~pyte.modes.DECOM` is set, cursor is bounded by top and and bottom margins, instead of ``[0; lines - 1]``.
5.264294
3.111628
1.691814
top, _bottom = self.margins or Margins(0, self.lines - 1) self.cursor.y = max(self.cursor.y - (count or 1), top)
def cursor_up(self, count=None)
Move cursor up the indicated # of lines in same column. Cursor stops at top margin. :param int count: number of lines to skip.
6.456885
6.729429
0.9595
_top, bottom = self.margins or Margins(0, self.lines - 1) self.cursor.y = min(self.cursor.y + (count or 1), bottom)
def cursor_down(self, count=None)
Move cursor down the indicated # of lines in same column. Cursor stops at bottom margin. :param int count: number of lines to skip.
7.143523
6.602462
1.081948
# Handle the case when we've just drawn in the last column # and would wrap the line on the next :meth:`draw()` call. if self.cursor.x == self.columns: self.cursor.x -= 1 self.cursor.x -= count or 1 self.ensure_hbounds()
def cursor_back(self, count=None)
Move cursor left the indicated # of columns. Cursor stops at left margin. :param int count: number of columns to skip.
10.167242
10.765308
0.944445
column = (column or 1) - 1 line = (line or 1) - 1 # If origin mode (DECOM) is set, line number are relative to # the top scrolling margin. if self.margins is not None and mo.DECOM in self.mode: line += self.margins.top # Cursor is not allowed to...
def cursor_position(self, line=None, column=None)
Set the cursor to a specific `line` and `column`. Cursor is allowed to move out of the scrolling region only when :data:`~pyte.modes.DECOM` is reset, otherwise -- the position doesn't change. :param int line: line number to move the cursor to. :param int column: column number t...
5.404924
5.127125
1.054182
self.cursor.y = (line or 1) - 1 # If origin mode (DECOM) is set, line number are relative to # the top scrolling margin. if mo.DECOM in self.mode: self.cursor.y += self.margins.top # FIXME: should we also restrict the cursor to the scrolling ...
def cursor_to_line(self, line=None)
Move cursor to a specific line in the current column. :param int line: line number to move the cursor to.
10.433176
12.44341
0.83845
self.dirty.update(range(self.lines)) for y in range(self.lines): for x in range(self.columns): self.buffer[y][x] = self.buffer[y][x]._replace(data="E")
def alignment_display(self)
Fills screen with uppercase E's for screen focus and alignment.
5.243856
3.736251
1.403508
replace = {} # Fast path for resetting all attributes. if not attrs or attrs == (0, ): self.cursor.attrs = self.default_char return else: attrs = list(reversed(attrs)) while attrs: attr = attrs.pop() if attr =...
def select_graphic_rendition(self, *attrs)
Set display attributes. :param list attrs: a list of display attributes to set.
3.213616
3.272947
0.981872
# We only implement "primary" DA which is the only DA request # VT102 understood, see ``VT102ID`` in ``linux/drivers/tty/vt.c``. if mode == 0 and not kwargs.get("private"): self.write_process_input(ctrl.CSI + "?6c")
def report_device_attributes(self, mode=0, **kwargs)
Report terminal identity. .. versionadded:: 0.5.0 .. versionchanged:: 0.7.0 If ``private`` keyword argument is set, the method does nothing. This behaviour is consistent with VT220 manual.
25.332228
19.776926
1.280898
if mode == 5: # Request for terminal status. self.write_process_input(ctrl.CSI + "0n") elif mode == 6: # Request for cursor position. x = self.cursor.x + 1 y = self.cursor.y + 1 # "Origin mode (DECOM) selects line numbering." if m...
def report_device_status(self, mode)
Report terminal status or cursor position. :param int mode: if 5 -- terminal status, 6 -- cursor position, otherwise a noop. .. versionadded:: 0.5.0
6.191528
5.435065
1.139182
if event not in ["prev_page", "next_page"]: while self.history.position < self.history.size: self.next_page()
def before_event(self, event)
Ensure a screen is at the bottom of the history buffer. :param str event: event name, for example ``"linefeed"``.
7.630309
7.933999
0.961723
if event in ["prev_page", "next_page"]: for line in self.buffer.values(): for x in line: if x > self.columns: line.pop(x) # If we're at the bottom of the history buffer and `DECTCEM` # mode is set -- show the curso...
def after_event(self, event)
Ensure all lines on a screen have proper width (:attr:`columns`). Extra characters are truncated, missing characters are filled with whitespace. :param str event: event name, for example ``"linefeed"``.
8.722448
8.357073
1.043721
super(HistoryScreen, self).erase_in_display(how, *args, **kwargs) if how == 3: self._reset_history()
def erase_in_display(self, how=0, *args, **kwargs)
Overloaded to reset history state.
4.757756
3.352547
1.419147
top, bottom = self.margins or Margins(0, self.lines - 1) if self.cursor.y == bottom: self.history.top.append(self.buffer[top]) super(HistoryScreen, self).index()
def index(self)
Overloaded to update top history with the removed lines.
9.998446
7.768658
1.287023
if self.history.position > self.lines and self.history.top: mid = min(len(self.history.top), int(math.ceil(self.lines * self.history.ratio))) self.history.bottom.extendleft( self.buffer[y] for y in range(self.lines - 1, self...
def prev_page(self)
Move the screen page up through the history buffer. Page size is defined by ``history.ratio``, so for instance ``ratio = .5`` means that half the screen is restored from history on page switch.
3.304693
3.064532
1.078368
if self.history.position < self.history.size and self.history.bottom: mid = min(len(self.history.bottom), int(math.ceil(self.lines * self.history.ratio))) self.history.top.extend(self.buffer[y] for y in range(mid)) self.history = self.history \...
def next_page(self)
Move the screen page down through the history buffer.
3.766107
3.548038
1.061462
if self.listener is not None: warnings.warn("As of version 0.6.0 the listener queue is " "restricted to a single element. Existing " "listener {0} will be replaced." .format(self.listener), DeprecationWarning) ...
def attach(self, screen)
Adds a given screen to the listener queue. :param pyte.screens.Screen screen: a screen to attach to.
5.325392
4.963192
1.072977
send = self._send_to_parser draw = self.listener.draw match_text = self._text_pattern.match taking_plain_text = self._taking_plain_text length = len(data) offset = 0 while offset < length: if taking_plain_text: match = match_t...
def feed(self, data)
Consume some data and advances the state as necessary. :param str data: a blob of data to feed from.
3.470231
3.666207
0.946545
global is_shutting_down is_shutting_down = True for task in app["websockets"]: task.cancel() try: await task except asyncio.CancelledError: pass
async def on_shutdown(app)
Closes all WS connections on shutdown.
3.334846
2.853949
1.168503
D = len(V[0]) N = len(V) result = 0.0 for v, w in zip(V, W): result += sum([(v[i] - w[i])**2.0 for i in range(D)]) return np.sqrt(result/N)
def rmsd(V, W)
Calculate Root-mean-square deviation from two sets of vectors V and W. Parameters ---------- V : array (N,D) matrix, where N is points and D is dimension. W : array (N,D) matrix, where N is points and D is dimension. Returns ------- rmsd : float Root-mean-square dev...
2.256982
2.971889
0.759443
if translate: Q = Q - centroid(Q) P = P - centroid(P) P = kabsch_rotate(P, Q) return rmsd(P, Q)
def kabsch_rmsd(P, Q, translate=False)
Rotate matrix P unto Q using Kabsch algorithm and calculate the RMSD. Parameters ---------- P : array (N,D) matrix, where N is points and D is dimension. Q : array (N,D) matrix, where N is points and D is dimension. translate : bool Use centroids to translate vector P and Q ...
3.144368
4.382146
0.717541
U = kabsch(P, Q) # Rotate P P = np.dot(P, U) return P
def kabsch_rotate(P, Q)
Rotate matrix P unto matrix Q using Kabsch algorithm. Parameters ---------- P : array (N,D) matrix, where N is points and D is dimension. Q : array (N,D) matrix, where N is points and D is dimension. Returns ------- P : array (N,D) matrix, where N is points and D is...
4.486374
10.689507
0.419699
# Computation of the covariance matrix C = np.dot(np.transpose(P), Q) # Computation of the optimal rotation matrix # This can be done using singular value decomposition (SVD) # Getting the sign of the det(V)*(W) to decide # whether we need to correct our rotation matrix to ensure a # ...
def kabsch(P, Q)
Using the Kabsch algorithm with two sets of paired point P and Q, centered around the centroid. Each vector set is represented as an NxD matrix, where D is the the dimension of the space. The algorithm works in three steps: - a centroid translation of P and Q (assumed done before this function ca...
2.9927
2.902829
1.03096
rot = quaternion_rotate(P, Q) P = np.dot(P, rot) return rmsd(P, Q)
def quaternion_rmsd(P, Q)
Rotate matrix P unto Q and calculate the RMSD based on doi:10.1016/1049-9660(91)90036-O Parameters ---------- P : array (N,D) matrix, where N is points and D is dimension. Q : array (N,D) matrix, where N is points and D is dimension. Returns ------- rmsd : float
4.180674
5.131698
0.814676
Wt_r = makeW(*r).T Q_r = makeQ(*r) rot = Wt_r.dot(Q_r)[:3, :3] return rot
def quaternion_transform(r)
Get optimal rotation note: translation will be zero when the centroids of each molecule are the same
6.033924
7.079361
0.852326
W = np.asarray([ [r4, r3, -r2, r1], [-r3, r4, r1, r2], [r2, -r1, r4, r3], [-r1, -r2, -r3, r4]]) return W
def makeW(r1, r2, r3, r4=0)
matrix involved in quaternion rotation
1.930695
1.76936
1.091182
Q = np.asarray([ [r4, -r3, r2, r1], [r3, r4, -r1, r2], [-r2, r1, r4, r3], [-r1, -r2, -r3, r4]]) return Q
def makeQ(r1, r2, r3, r4=0)
matrix involved in quaternion rotation
1.893034
1.721604
1.099576
N = X.shape[0] W = np.asarray([makeW(*Y[k]) for k in range(N)]) Q = np.asarray([makeQ(*X[k]) for k in range(N)]) Qt_dot_W = np.asarray([np.dot(Q[k].T, W[k]) for k in range(N)]) W_minus_Q = np.asarray([W[k] - Q[k] for k in range(N)]) A = np.sum(Qt_dot_W, axis=0) eigen = np.linalg.eigh(A)...
def quaternion_rotate(X, Y)
Calculate the rotation Parameters ---------- X : array (N,D) matrix, where N is points and D is dimension. Y: array (N,D) matrix, where N is points and D is dimension. Returns ------- rot : matrix Rotation matrix (D,D)
2.905195
2.99611
0.969655
# Find unique atoms unique_atoms = np.unique(p_atoms) # generate full view from q shape to fill in atom view on the fly view_reorder = np.zeros(q_atoms.shape, dtype=int) for atom in unique_atoms: p_atom_idx, = np.where(p_atoms == atom) q_atom_idx, = np.where(q_atoms == atom)...
def reorder_distance(p_atoms, q_atoms, p_coord, q_coord)
Re-orders the input atom list and xyz coordinates by atom type and then by distance of each atom from the centroid. Parameters ---------- atoms : array (N,1) matrix, where N is points holding the atoms' names coord : array (N,D) matrix, where N is points and D is dimension Retu...
2.802602
2.876475
0.974318
# should be kabasch here i think distances = cdist(A, B, 'euclidean') # Perform Hungarian analysis on distance matrix between atoms of 1st # structure and trial structure indices_a, indices_b = linear_sum_assignment(distances) return indices_b
def hungarian(A, B)
Hungarian reordering. Assume A and B are coordinates for atoms of SAME type only
11.475031
11.142329
1.029859
c = [0] * n yield elements i = 0 while i < n: if c[i] < i: if i % 2 == 0: elements[0], elements[i] = elements[i], elements[0] else: elements[c[i]], elements[i] = elements[i], elements[c[i]] yield elements c[i] +...
def generate_permutations(elements, n)
Heap's algorithm for generating all n! permutations in a list https://en.wikipedia.org/wiki/Heap%27s_algorithm
1.983996
1.956863
1.013865
rmsd_min = np.inf view_min = None # Sets initial ordering for row indices to [0, 1, 2, ..., len(A)], used in # brute-force method num_atoms = A.shape[0] initial_order = list(range(num_atoms)) for reorder_indices in generate_permutations(initial_order, num_atoms): # Re-order...
def brute_permutation(A, B)
Re-orders the input atom list and xyz coordinates using the brute force method of permuting all rows of the input coordinates Parameters ---------- A : array (N,D) matrix, where N is points and D is dimension B : array (N,D) matrix, where N is points and D is dimension Returns ...
4.62026
4.359204
1.059886
# Find unique atoms unique_atoms = np.unique(p_atoms) # generate full view from q shape to fill in atom view on the fly view_reorder = np.zeros(q_atoms.shape, dtype=int) view_reorder -= 1 for atom in unique_atoms: p_atom_idx, = np.where(p_atoms == atom) q_atom_idx, = np.w...
def reorder_brute(p_atoms, q_atoms, p_coord, q_coord)
Re-orders the input atom list and xyz coordinates using all permutation of rows (using optimized column results) Parameters ---------- p_atoms : array (N,1) matrix, where N is points holding the atoms' names q_atoms : array (N,1) matrix, where N is points holding the atoms' names ...
3.174826
3.037962
1.045051
min_rmsd = np.inf min_swap = None min_reflection = None min_review = None tmp_review = None swap_mask = [1,-1,-1,1,-1,1] reflection_mask = [1,-1,-1,-1,1,1,1,-1] for swap, i in zip(AXIS_SWAPS, swap_mask): for reflection, j in zip(AXIS_REFLECTIONS, reflection_mask): ...
def check_reflections(p_atoms, q_atoms, p_coord, q_coord, reorder_method=reorder_hungarian, rotation_method=kabsch_rmsd, keep_stereo=False)
Minimize RMSD using reflection planes for molecule P and Q Warning: This will affect stereo-chemistry Parameters ---------- p_atoms : array (N,1) matrix, where N is points holding the atoms' names q_atoms : array (N,1) matrix, where N is points holding the atoms' names p_coord ...
2.57875
2.468999
1.044452
N, D = V.shape fmt = "{:2s}" + (" {:15."+str(decimals)+"f}")*3 out = list() out += [str(N)] out += [title] for i in range(N): atom = atoms[i] atom = atom[0].upper() + atom[1:] out += [fmt.format(atom, V[i, 0], V[i, 1], V[i, 2])] return "\n".join(out)
def set_coordinates(atoms, V, title="", decimals=8)
Print coordinates V with corresponding atoms to stdout in XYZ format. Parameters ---------- atoms : list List of atomic types V : array (N,3) matrix of atomic coordinates title : string (optional) Title of molecule decimals : int (optional) number of decimals for ...
2.792078
3.101023
0.900373
print(set_coordinates(atoms, V, title=title)) return
def print_coordinates(atoms, V, title="")
Print coordinates V with corresponding atoms to stdout in XYZ format. Parameters ---------- atoms : list List of element types V : array (N,3) matrix of atomic coordinates title : string (optional) Title of molecule
9.877104
12.839799
0.769257
if fmt == "xyz": get_func = get_coordinates_xyz elif fmt == "pdb": get_func = get_coordinates_pdb else: exit("Could not recognize file format: {:s}".format(fmt)) return get_func(filename)
def get_coordinates(filename, fmt)
Get coordinates from filename in format fmt. Supports XYZ and PDB. Parameters ---------- filename : string Filename to read fmt : string Format of filename. Either xyz or pdb. Returns ------- atoms : list List of atomic types V : array (N,3) where N is num...
3.092142
3.580817
0.86353
# PDB files tend to be a bit of a mess. The x, y and z coordinates # are supposed to be in column 31-38, 39-46 and 47-54, but this is # not always the case. # Because of this the three first columns containing a decimal is used. # Since the format doesn't require a space between columns, we us...
def get_coordinates_pdb(filename)
Get coordinates from the first chain in a pdb file and return a vectorset with all the coordinates. Parameters ---------- filename : string Filename to read Returns ------- atoms : list List of atomic types V : array (N,3) where N is number of atoms
3.374658
3.334298
1.012104
f = open(filename, 'r') V = list() atoms = list() n_atoms = 0 # Read the first line to obtain the number of atoms to read try: n_atoms = int(f.readline()) except ValueError: exit("error: Could not obtain the number of atoms in the .xyz file.") # Skip the title lin...
def get_coordinates_xyz(filename)
Get coordinates from filename and return a vectorset with all the coordinates, in XYZ format. Parameters ---------- filename : string Filename to read Returns ------- atoms : list List of atomic types V : array (N,3) where N is number of atoms
3.192504
3.109896
1.026563
string_parts = [] if self.data_stream: string_parts.append('data stream: {0:s}'.format(self.data_stream)) if self.inode is not None: string_parts.append('inode: {0:d}'.format(self.inode)) if self.location is not None: string_parts.append('location: {0:s}'.format(self.location)) ...
def comparable(self)
str: comparable representation of the path specification.
2.819988
2.492711
1.131294
format_specification = specification.FormatSpecification( self.type_indicator) # TODO: add support for signature chains so that we add the 'BZ' at # offset 0. # BZIP2 compressed steam signature. format_specification.AddNewSignature(b'\x31\x41\x59\x26\x53\x59', offset=4) return fo...
def GetFormatSpecification(self)
Retrieves the format specification. Returns: FormatSpecification: format specification or None if the format cannot be defined by a specification object.
12.075977
12.307755
0.981168
location = getattr(self.path_spec, 'location', None) if location and location.startswith(self._file_system.PATH_SEPARATOR): # The zip_info filename does not have the leading path separator # as the location string does. zip_path = location[1:] # Set of top level sub directories th...
def _EntriesGenerator(self)
Retrieves directory entries. Since a directory can contain a vast number of entries using a generator is more memory efficient. Yields: ZipPathSpec: a path specification.
3.271665
3.150082
1.038597
if self.entry_type != definitions.FILE_ENTRY_TYPE_DIRECTORY: return None return ZipDirectory(self._file_system, self.path_spec)
def _GetDirectory(self)
Retrieves a directory. Returns: ZipDirectory: a directory or None if not available.
7.072517
4.902534
1.442625
stat_object = super(ZipFileEntry, self)._GetStat() if self._zip_info is not None: # File data stat information. stat_object.size = getattr(self._zip_info, 'file_size', None) # Ownership and permissions stat information. if self._external_attributes != 0: if self._creator_s...
def _GetStat(self)
Retrieves information about the file entry. Returns: VFSStat: a stat object.
3.545521
3.510841
1.009878
if self._directory is None: self._directory = self._GetDirectory() zip_file = self._file_system.GetZipFile() if self._directory and zip_file: for path_spec in self._directory.entries: location = getattr(path_spec, 'location', None) if location is None: continue ...
def _GetSubFileEntries(self)
Retrieves sub file entries. Yields: ZipFileEntry: a sub file entry.
2.967717
2.724393
1.089313
path = getattr(self.path_spec, 'location', None) if path is not None and not isinstance(path, py2to3.UNICODE_TYPE): try: path = path.decode(self._file_system.encoding) except UnicodeDecodeError: path = None return self._file_system.BasenamePath(path)
def name(self)
str: name of the file entry, without the full path.
3.518484
3.063402
1.148554
if self._zip_info is None: return None time_elements = getattr(self._zip_info, 'date_time', None) return dfdatetime_time_elements.TimeElements(time_elements)
def modification_time(self)
dfdatetime.DateTimeValues: modification time or None if not available.
6.33353
3.812967
1.66105
location = getattr(self.path_spec, 'location', None) if location is None: return None parent_location = self._file_system.DirnamePath(location) if parent_location is None: return None parent_path_spec = getattr(self.path_spec, 'parent', None) if parent_location == '': p...
def GetParentFileEntry(self)
Retrieves the parent file entry. Returns: ZipFileEntry: parent file entry or None if not available.
2.245843
2.076884
1.081352
if not self._zip_info: location = getattr(self.path_spec, 'location', None) if location is None: raise errors.PathSpecError('Path specification missing location.') if not location.startswith(self._file_system.LOCATION_ROOT): raise errors.PathSpecError('Invalid location in pat...
def GetZipInfo(self)
Retrieves the ZIP info object. Returns: zipfile.ZipInfo: a ZIP info object or None if not available. Raises: PathSpecError: if the path specification is incorrect.
2.450241
2.324339
1.054167
stat_object = super(FVDEFileEntry, self)._GetStat() stat_object.size = self._fvde_volume.get_size() return stat_object
def _GetStat(self)
Retrieves information about the file entry. Returns: VFSStat: a stat object.
9.592112
8.147826
1.17726
if not scan_node or not scan_node.path_spec: raise errors.ScannerError('Invalid scan node.') volume_system = apfs_volume_system.APFSVolumeSystem() volume_system.Open(scan_node.path_spec) volume_identifiers = self._source_scanner.GetVolumeIdentifiers( volume_system) if not volume...
def _GetAPFSVolumeIdentifiers(self, scan_node)
Determines the APFS volume identifiers. Args: scan_node (SourceScanNode): scan node. Returns: list[str]: APFS volume identifiers. Raises: ScannerError: if the format of or within the source is not supported or the the scan node is invalid. UserAbort: if the user requeste...
3.006446
2.901901
1.036026
if not scan_node or not scan_node.path_spec: raise errors.ScannerError('Invalid scan node.') volume_system = tsk_volume_system.TSKVolumeSystem() volume_system.Open(scan_node.path_spec) volume_identifiers = self._source_scanner.GetVolumeIdentifiers( volume_system) if not volume_i...
def _GetTSKPartitionIdentifiers(self, scan_node)
Determines the TSK partition identifiers. Args: scan_node (SourceScanNode): scan node. Returns: list[str]: TSK partition identifiers. Raises: ScannerError: if the format of or within the source is not supported or the scan node is invalid or if the volume for a specific identi...
3.09919
3.035539
1.020968
if not scan_node or not scan_node.path_spec: raise errors.ScannerError('Invalid scan node.') volume_system = vshadow_volume_system.VShadowVolumeSystem() volume_system.Open(scan_node.path_spec) volume_identifiers = self._source_scanner.GetVolumeIdentifiers( volume_system) if not ...
def _GetVSSStoreIdentifiers(self, scan_node)
Determines the VSS store identifiers. Args: scan_node (SourceScanNode): scan node. Returns: list[str]: VSS store identifiers. Raises: ScannerError: if the format the scan node is invalid or no mediator is provided and VSS store identifiers are found. UserAbort: if the us...
3.440593
3.078172
1.117739
normalized_volume_identifiers = [] for volume_identifier in volume_identifiers: if isinstance(volume_identifier, int): volume_identifier = '{0:s}{1:d}'.format(prefix, volume_identifier) elif not volume_identifier.startswith(prefix): try: volume_identifier = int(volume...
def _NormalizedVolumeIdentifiers( self, volume_system, volume_identifiers, prefix='v')
Normalizes volume identifiers. Args: volume_system (VolumeSystem): volume system. volume_identifiers (list[int|str]): allowed volume identifiers, formatted as an integer or string with prefix. prefix (Optional[str]): volume identifier prefix. Returns: list[str]: volume identi...
1.82296
1.819319
1.002001
if not scan_node or not scan_node.path_spec: raise errors.ScannerError('Invalid or missing scan node.') credentials = credentials_manager.CredentialsManager.GetCredentials( scan_node.path_spec) if not credentials: raise errors.ScannerError('Missing credentials for scan node.') ...
def _ScanEncryptedVolume(self, scan_context, scan_node)
Scans an encrypted volume scan node for volume and file systems. Args: scan_context (SourceScannerContext): source scanner context. scan_node (SourceScanNode): volume scan node. Raises: ScannerError: if the format of or within the source is not supported, the scan node is invalid, ...
3.222453
3.019677
1.067152
if not scan_node or not scan_node.path_spec: raise errors.ScannerError('Invalid or missing file system scan node.') base_path_specs.append(scan_node.path_spec)
def _ScanFileSystem(self, scan_node, base_path_specs)
Scans a file system scan node for file systems. Args: scan_node (SourceScanNode): file system scan node. base_path_specs (list[PathSpec]): file system base path specifications. Raises: ScannerError: if the scan node is invalid.
3.519789
3.368532
1.044903
if not scan_node or not scan_node.path_spec: raise errors.ScannerError('Invalid or missing scan node.') if scan_context.IsLockedScanNode(scan_node.path_spec): # The source scanner found a locked volume and we need a credential to # unlock it. self._ScanEncryptedVolume(scan_context,...
def _ScanVolume(self, scan_context, scan_node, base_path_specs)
Scans a volume scan node for volume and file systems. Args: scan_context (SourceScannerContext): source scanner context. scan_node (SourceScanNode): volume scan node. base_path_specs (list[PathSpec]): file system base path specifications. Raises: ScannerError: if the format of or withi...
3.146539
3.142617
1.001248
if not scan_node or not scan_node.path_spec: raise errors.ScannerError('Invalid scan node.') if scan_node.type_indicator == definitions.TYPE_INDICATOR_APFS_CONTAINER: volume_identifiers = self._GetAPFSVolumeIdentifiers(scan_node) elif scan_node.type_indicator == definitions.TYPE_INDICATOR...
def _ScanVolumeSystemRoot(self, scan_context, scan_node, base_path_specs)
Scans a volume system root scan node for volume and file systems. Args: scan_context (SourceScannerContext): source scanner context. scan_node (SourceScanNode): volume system root scan node. base_path_specs (list[PathSpec]): file system base path specifications. Raises: ScannerError: i...
2.120546
2.119101
1.000682
if not source_path: raise errors.ScannerError('Invalid source path.') # Note that os.path.exists() does not support Windows device paths. if (not source_path.startswith('\\\\.\\') and not os.path.exists(source_path)): raise errors.ScannerError( 'No such device, file or di...
def GetBasePathSpecs(self, source_path)
Determines the base path specifications. Args: source_path (str): source path. Returns: list[PathSpec]: path specifications. Raises: ScannerError: if the source path does not exists, or if the source path is not a file or directory, or if the format of or within the source ...
2.374848
2.285548
1.039071
if not scan_node or not scan_node.path_spec: raise errors.ScannerError('Invalid or missing file system scan node.') file_system = resolver.Resolver.OpenFileSystem(scan_node.path_spec) if not file_system: return try: path_resolver = windows_path_resolver.WindowsPathResolver( ...
def _ScanFileSystem(self, scan_node, base_path_specs)
Scans a file system scan node for file systems. This method checks if the file system contains a known Windows directory. Args: scan_node (SourceScanNode): file system scan node. base_path_specs (list[PathSpec]): file system base path specifications. Raises: ScannerError: if the scan no...
2.699178
2.530191
1.066788
result = False for windows_path in self._WINDOWS_DIRECTORIES: windows_path_spec = path_resolver.ResolvePath(windows_path) result = windows_path_spec is not None if result: self._windows_directory = windows_path break return result
def _ScanFileSystemForWindowsDirectory(self, path_resolver)
Scans a file system for a known Windows directory. Args: path_resolver (WindowsPathResolver): Windows path resolver. Returns: bool: True if a known Windows directory was found.
3.490393
3.756427
0.929179
path_spec = self._path_resolver.ResolvePath(windows_path) if path_spec is None: return None return self._file_system.GetFileObjectByPathSpec(path_spec)
def OpenFile(self, windows_path)
Opens the file specificed by the Windows path. Args: windows_path (str): Windows path to the file. Returns: FileIO: file-like object or None if the file does not exist.
3.313993
3.526081
0.939852
windows_path_specs = self.GetBasePathSpecs(source_path) if (not windows_path_specs or self._source_type == definitions.SOURCE_TYPE_FILE): return False file_system_path_spec = windows_path_specs[0] self._file_system = resolver.Resolver.OpenFileSystem(file_system_path_spec) if fil...
def ScanForWindowsVolume(self, source_path)
Scans for a Windows volume. Args: source_path (str): source path. Returns: bool: True if a Windows volume was found. Raises: ScannerError: if the source path does not exists, or if the source path is not a file or directory, or if the format of or within the source f...
2.716804
2.767559
0.981661
if definitions.FORMAT_CATEGORY_ARCHIVE in format_categories: cls._archive_remainder_list = None cls._archive_scanner = None cls._archive_store = None if definitions.FORMAT_CATEGORY_COMPRESSED_STREAM in format_categories: cls._compressed_stream_remainder_list = None cls._compr...
def _FlushCache(cls, format_categories)
Flushes the cached objects for the specified format categories. Args: format_categories (set[str]): format categories.
1.756878
1.71983
1.021542
signature_scanner = pysigscan.scanner() signature_scanner.set_scan_buffer_size(cls._SCAN_BUFFER_SIZE) for format_specification in specification_store.specifications: for signature in format_specification.signatures: pattern_offset = signature.offset if pattern_offset is None: ...
def _GetSignatureScanner(cls, specification_store)
Initializes a signature scanner based on a specification store. Args: specification_store (FormatSpecificationStore): specification store. Returns: pysigscan.scanner: signature scanner.
2.789685
2.755229
1.012506
specification_store = specification.FormatSpecificationStore() remainder_list = [] for analyzer_helper in iter(cls._analyzer_helpers.values()): if not analyzer_helper.IsEnabled(): continue if format_category in analyzer_helper.format_categories: format_specification = anal...
def _GetSpecificationStore(cls, format_category)
Retrieves the specification store for specified format category. Args: format_category (str): format category. Returns: tuple[FormatSpecificationStore, list[AnalyzerHelper]]: a format specification store and remaining analyzer helpers that do not have a format specification.
3.150068
2.568574
1.226388
type_indicator_list = [] file_object = resolver.Resolver.OpenFileObject( path_spec, resolver_context=resolver_context) scan_state = pysigscan.scan_state() try: signature_scanner.scan_file_object(scan_state, file_object) for scan_result in iter(scan_state.scan_results): ...
def _GetTypeIndicators( cls, signature_scanner, specification_store, remainder_list, path_spec, resolver_context=None)
Determines if a file contains a supported format types. Args: signature_scanner (pysigscan.scanner): signature scanner. specification_store (FormatSpecificationStore): specification store. remainder_list (list[AnalyzerHelper]): remaining analyzer helpers that do not have a format specif...
2.732823
2.717406
1.005674
if analyzer_helper.type_indicator not in cls._analyzer_helpers: raise KeyError( 'Analyzer helper object not set for type indicator: {0:s}.'.format( analyzer_helper.type_indicator)) analyzer_helper = cls._analyzer_helpers[analyzer_helper.type_indicator] cls._FlushCache(an...
def DeregisterHelper(cls, analyzer_helper)
Deregisters a format analyzer helper. Args: analyzer_helper (AnalyzerHelper): analyzer helper. Raises: KeyError: if analyzer helper object is not set for the corresponding type indicator.
3.383931
2.49309
1.357324
if (cls._archive_remainder_list is None or cls._archive_store is None): specification_store, remainder_list = cls._GetSpecificationStore( definitions.FORMAT_CATEGORY_ARCHIVE) cls._archive_remainder_list = remainder_list cls._archive_store = specification_store if cls._a...
def GetArchiveTypeIndicators(cls, path_spec, resolver_context=None)
Determines if a file contains a supported archive types. Args: path_spec (PathSpec): path specification. resolver_context (Optional[Context]): resolver context, where None represents the built-in context which is not multi process safe. Returns: list[str]: supported format type ind...
3.708283
4.196292
0.883705
if (cls._compressed_stream_remainder_list is None or cls._compressed_stream_store is None): specification_store, remainder_list = cls._GetSpecificationStore( definitions.FORMAT_CATEGORY_COMPRESSED_STREAM) cls._compressed_stream_remainder_list = remainder_list cls._compressed...
def GetCompressedStreamTypeIndicators(cls, path_spec, resolver_context=None)
Determines if a file contains a supported compressed stream types. Args: path_spec (PathSpec): path specification. resolver_context (Optional[Context]): resolver context, where None represents the built-in context which is not multi process safe. Returns: list[str]: supported forma...
3.083316
3.345134
0.921732
if (cls._file_system_remainder_list is None or cls._file_system_store is None): specification_store, remainder_list = cls._GetSpecificationStore( definitions.FORMAT_CATEGORY_FILE_SYSTEM) cls._file_system_remainder_list = remainder_list cls._file_system_store = specification_...
def GetFileSystemTypeIndicators(cls, path_spec, resolver_context=None)
Determines if a file contains a supported file system types. Args: path_spec (PathSpec): path specification. resolver_context (Optional[Context]): resolver context, where None represents the built-in context which is not multi process safe. Returns: list[str]: supported format type...
3.138577
3.447787
0.910316