forgi 2.0.0 documentation

«  forgi.threedee.utilities package   ::   Contents   ::   forgi.threedee.utilities.mcannotate module  »

forgi.threedee.utilities.graph_pdb module

class forgi.threedee.utilities.graph_pdb.VirtualAtomsLookup(cg, given_atom_names=None, sidechain=True)[source]

Bases: future.types.newobject.newobject

An object with a dict-like interface that calculates the virtual atom positions on demand.

Parameters:cg – The coarse grain structure, for which the virtual atoms are generated.
..note ::
If cg is modified, new virtual atom positions are calculated.
keys()[source]
forgi.threedee.utilities.graph_pdb.add_loop_information_from_pdb_chains(bg)[source]
forgi.threedee.utilities.graph_pdb.add_stem_information_from_pdb_chains(cg)[source]

Get the 3D information of the stems.

Output the mid points of the helices as well as the ‘twist’ vectors which describe the projection of the (ca - mids) vectors onto the plane perpendicular to the axis of the helix.

Add all of this information to the BulgeGraph data structure.

Parameters:
  • bg – The BulgeGraph.
  • chain – The Bio.PDB chain representation of the 3D structure.
forgi.threedee.utilities.graph_pdb.add_virtual_residues(bg, element)[source]

Create all of the virtual residues and the associated bases and inverses for the given stem.

Note

This is a low-level function used if only the virtual residues of a single stems should be added. To add the virtual residues for all stems, use cg.add_all_virtual_residues

Parameters:
  • bg – The CoarseGrainRNA bulge graph containing the stem
  • element – The name of the stem to be included
forgi.threedee.utilities.graph_pdb.base_normals(pdb_filename)[source]

Return a list of the normals for each base in the structure.

As defined by the average of the cross products between the C2-C5 and C2-C6 vectors and the N3-C6 and N3-C5 vectors. The origin of the vector will be the centroid of these four atoms.

Parameters:pdb_filename – The name of the pdb file containing the structure
Returns:A list of pairs containing the origin the normal as well as the normal itself.
forgi.threedee.utilities.graph_pdb.bounding_boxes(bg, s, i)[source]

Return the bounding boxes of the two nucleotides at the i’th position on the stem.

Parameters:
  • bg – A BulgeGraph where bg.chains is not None
  • s – The stem identifier
  • i – The i’th base-pair in the stem
Returns:

(origin, basis, [(c1, c2), (c1, c2)]) The bases and the corners defining the bounding box of the two nucleotides

forgi.threedee.utilities.graph_pdb.calc_R(xc, yc, p)[source]

calculate the distance of each 2D points from the center (xc, yc)

forgi.threedee.utilities.graph_pdb.circle_error(c, p)[source]
forgi.threedee.utilities.graph_pdb.circle_fit(p)[source]
forgi.threedee.utilities.graph_pdb.cylinder_works(cg, cylinders_to_stems, tv, c, r=4.0)[source]

Check if all of these points are inside the cylinder.

forgi.threedee.utilities.graph_pdb.element_coord_system(cg, d)[source]

Get a coordinate system for a particular coarse grain element.

If an element has an axis vector, a, twist vectors t1 and t2, then the coordinate system will be a normalized version of the axis a, the second, v2, will be equal to norm((t1 + t2) / 2.)

And the third will be equal to a x v2.

forgi.threedee.utilities.graph_pdb.element_distance(cg, l1, l2)[source]

Calculate the distance between the two closest points of these two elements.

forgi.threedee.utilities.graph_pdb.extract_define_residues(define, chain)[source]

Extract the residues in the define and return them as a new chain.

forgi.threedee.utilities.graph_pdb.f_2(c, p)[source]

calculate the algebraic distance between the data points and the mean circle centered at c=(xc, yc)

forgi.threedee.utilities.graph_pdb.f_3(vec, points, est)[source]

calculate the optimal circle for the points (p) projected onto the plane orthogonal to v

forgi.threedee.utilities.graph_pdb.fit_circle(mids, points, start_pos, end_pos)[source]

Calculate the projection of points on the plane normal to vec and fit a circle to them.

forgi.threedee.utilities.graph_pdb.get_angle_stat_geometry(stem1_vec, twist1, stem2_vec, twist2, bulge_vec)[source]
Parameters:
  • stem1_vec – The vector of the first stem, pointing TOWARDS the bulge
  • twist1 – The twist vector at the side of stem1 closest to the bulge
  • stem2_vec – The vector of the second stem, pointing AWAY FROM the bulge
  • twist2 – The twist vector at the side of stem2 closest to the bulge
  • bulge_vec – The vector from stem1 to stem2
Returns:

T 6-tuple: u,v (the orientation parameters),

t (twist parameter) and r1, u1, v1 (the seperation parameters)

A
stem1 /
/ stem2
V /
———>

bulge

forgi.threedee.utilities.graph_pdb.get_basepair_center(cg, pos)[source]

The center of a basepair, as defined in doi: 10.1261/rna.305307

Parameters:pos – The number of one of the two pairing bases
forgi.threedee.utilities.graph_pdb.get_basepair_plane(cg, pos)[source]

The plane of the basepair, as defined in figure 13 of doi: 10.1261/rna.305307

Parameters:pos – The number of one of the two pairing bases
forgi.threedee.utilities.graph_pdb.get_broken_ml_deviation(cg, broken_ml_name, fixed_stem_name, virtual_stat)[source]

If we assgin a stat to a broken ml-segment, how much would the attached stem deviate from its true location.

Calculates the position of a ‘“virtual stem”, which would be placed after the broken ml-segment, if it was a true ml-segment with the virtual stat assigned. Then calculates the deviation between this virtual stem and the actual stem.

Parameters:
  • cg – The CoarseGrainRNA
  • broken_ml_name – The name of the ml-segment of interest. It should not be part of cg.mst.
  • fixed_stem_name – The name of a stem (e.g. “s0”) attached to the broken ml segment. This stem will be used as reference, For the other stem attached to the broken ml-segment (original_stem), the virtual stem position will be calculated.
  • virtual_stat – The stat assigned to the broken ml segment, in the direction from fixed_stem_name to the other stem.
Returns:

A triple: positional_deviation, angular_deviation and twist_deviation. positional_deviation measures how far the start of the virtual stem is from the start of the true (“original”) stem. Angular deviation measures (in radians) the differece in the stem’s orientation. twist_deviation measures the angle (in radians) between the two stem’s twist vectors.

forgi.threedee.utilities.graph_pdb.get_bulge_centroid(chain, define)[source]
forgi.threedee.utilities.graph_pdb.get_centroid(chain, residue_num)[source]
Parameters:residue_num – A list of integers
forgi.threedee.utilities.graph_pdb.get_encompassing_cylinders(cg, radius=6.0)[source]
forgi.threedee.utilities.graph_pdb.get_furthest_c_alpha(cg, chain, stem_end, d)[source]

Get the position of the c-alpha atom furthest from the end of the stem.

forgi.threedee.utilities.graph_pdb.get_incomplete_elements(cg)[source]

Get an estimated list of cg-elements which have missing residues in the PDB.

One of many problems with PDB data are residues, for which no coordinates could be determined experimentally. This function gives an estimated list of cg-elements, which are affected by missing residues.

forgi.threedee.utilities.graph_pdb.get_residue_type(i, stem_len)[source]

Each nucleotide will be classified according to its position within the stem. That way, the distribution of surrounding nucleotides will be conditioned on the type of nucleotides.

This is important due to the fact that nucleotides at the end of a stem may have other stem nucleotides in the direction of the stem vector. Nucleotides, in the middle shoubulge not due to the excluded volume of the stem they occupy.

Parameters:
  • i – The position of the nucleotide.
  • stem_len – The length of the stem.
Returns:

The type of nucleotide position.

forgi.threedee.utilities.graph_pdb.get_stem_orientation_parameters(stem1_vec, twist1, stem2_vec, twist2)[source]

Return a parameterization of the orientation of stem2 with respect to stem1.

stem1 -> bulge -> stem2

Parameters:
  • stem1_vec – The vector representing the axis of stem1
  • twist1 – The twist of stem1 closest to the bulge
  • stem2_vec – The vector representing the axis of stem2
Returns:

(r,u,v,t) where r,u,v = the stem orientation in polar coordinates and t is the twist parameter.

forgi.threedee.utilities.graph_pdb.get_stem_separation_parameters(stem, twist, bulge)[source]

Parameterize the location of the bulge with respect to the stem.

Parameters:
  • stem – The stem vector.
  • bulge – the bulge vector.
forgi.threedee.utilities.graph_pdb.get_stem_twist_and_bulge_vecs(bg, bulge, connections)[source]

Return the vectors of the stems and of the twists between which we want to calculate angles.

The two vectors will be defined as follows:

s1e -> s1b -> b -> s2b -> s2e

The twists will be the two closest to the bulge.

Parameters:
  • bulge – The name of the bulge separating the two helices.
  • connections – The two stems that are connected to this bulge.
Returns:

(stem1, twist1, stem2, twist2, bulge)

forgi.threedee.utilities.graph_pdb.get_twist_angle(coords, twists)[source]

Get the angle of the twists with respect to each other.

Parameters:
  • coords – The coordinates of the ends of the stem.
  • twists – The two twist vectors.
Return angle:

The angle between the two twist vectors.

forgi.threedee.utilities.graph_pdb.get_twist_parameter(twist1, twist2, u_v)[source]

Calculate how much stem1 must be twisted for its twist vector to coincide with that of stem2.

Parameters:
  • twist1 – The twist notator of stem1
  • twist2 – The twist notator of stem2
  • u_v – The parameters u and v for rotating stem2 onto stem1
forgi.threedee.utilities.graph_pdb.junction_virtual_atom_distance(bg, bulge)[source]

Compute the distance between the O3’ atom and P’ atom of the two residues that flank the junction segment.

Parameters:
  • bg – The BulgeGraph containing the bulge.
  • bulge – The name of the bulge
Returns:

A single number corresponding to the distance above.

forgi.threedee.utilities.graph_pdb.junction_virtual_res_distance(bg, bulge)[source]

Compute the distance between the two virtual residues flanking a bulge region.

Parameters:
  • bg – The BulgeGraph containing the bulge.
  • bulge – The name of the bulge.
forgi.threedee.utilities.graph_pdb.pos_to_spos(bg, s1, i1, s2, i2)[source]

Convert the location of s2, i2 into the coordinate system defined by (s1, i1)

Parameters:
  • bg – The BulgeGraph containing the stems
  • s1 – The basis stem name
  • i1 – The basis res position
  • s2 – The stem containing the nucleotide to be converted
  • i2 – The nucleotide to be converted position
forgi.threedee.utilities.graph_pdb.profile(x)[source]
forgi.threedee.utilities.graph_pdb.stem2_orient_from_stem1(stem1, twist1, r_u_v)[source]

Calculate the orientation of the second stem, given its parameterization and the parameterization of stem1

Parameters:
  • stem1 – The vector representing the axis of stem1’s cylinder
  • twist1 – The twist factor of stem1.
  • r_u_v – The orientation of stem2 wrt stem1, a triple (r, u, v)
forgi.threedee.utilities.graph_pdb.stem2_orient_from_stem1_1(stem1_basis, r_u_v)[source]

Calculate the orientation of the second stem, given its parameterization and the parameterization of stem1

Parameters:
  • stem1 – The vector representing the axis of stem1’s cylinder
  • twist1 – The twist factor of stem1.
  • r_u_v – The orientation of stem2 wrt stem1, a triple (r, u, v)
forgi.threedee.utilities.graph_pdb.stem2_pos_from_stem1(stem1, twist1, params)[source]

Get the starting point of a second stem, given the parameters about where it’s located with respect to stem1

Parameters:
  • stem1 – The vector representing the axis of stem1’s cylinder
  • twist1 – The twist parameter of stem1
  • params – The parameters describing the position of stem2 wrt stem1
forgi.threedee.utilities.graph_pdb.stem2_pos_from_stem1_1(transposed_stem1_basis, params)[source]

Get the starting point of a second stem, given the parameters about where it’s located with respect to stem1

The params of the stat describe the change in the coordinate system of stem1. This function converts that to a carthesian vector the standard coordinate system

Parameters:
  • transposed_stem1_basis – The vtransposed basis of the first stem.
  • params – The parameters describing the position of stem2 wrt stem1 (i.e. the carthesian vector in standard coordinates pointing from stem1 to stem2)
forgi.threedee.utilities.graph_pdb.stem_from_chains(cg, chains, elem_name)[source]

This function combines get_mids and get_twists into one more efficient routine.

Parameters:
  • chains – A dictionary {chain_id: Biopython_PDB_chain}
  • elem_name – e.g. “s0”
forgi.threedee.utilities.graph_pdb.stem_stem_orientation(cg, s1, s2)[source]

Calculate the orientation of stem s2 in relation to stem s1 as described by 3 parameters:

  1. The distance between the closest points of the two stems.
  2. The angle between s1 and s2 in the plane formed by the axis of the first stem and the vector between the two points closest to each on both stems.
  3. The angle of s2 out of the plane formed by their axes.
Parameters:
  • bg – The BulgeGraph containing the stems.
  • s1 – The name of the first stem
  • s2 – The name of the second stem
Returns:

(x,y,z) where x,y and z are the parameters described in the description above.

forgi.threedee.utilities.graph_pdb.stem_vres_reference_atoms(bg, s, i)[source]

Calculate the position of each atom in the reference of the stem and virtual residue.

Parameters:
  • bg – The BulgeGraph
  • s – The stem identifier
  • i – The i’th base-pair in the stem
:return (origin, basis, [dict(atoms), dict(atoms)])
The origin of the coordinate system (vpos) The basis of the virtual residue Two dictionaries containing the positions of each atom in the coordinate system of the virtual residue
forgi.threedee.utilities.graph_pdb.total_helix_rotation(coords, twists, stem_len)[source]

Calculate the total rotation of the helix in radians from the twists.

When we calculate the angle between the two twists, we only know the true rotation modulo 2*pi (i.e. a rotation of 45 degrees could mean 45 degrees or 405 degrees). Depending on the number of nucleotides and knowledge of the ideal helix (which turns roughly 30 degrees per base-pair), this function outputs the correct result.

forgi.threedee.utilities.graph_pdb.twist2_from_twist1(stem_vec, twist1, angle)[source]

Get an orientation for the second twist which will place it an angle of angle from the first twist.

Parameters:
  • stem_vec – The vector of the stem.
  • twist1 – The vector of the first twist.
  • angle – The angular difference between the two twists.
forgi.threedee.utilities.graph_pdb.twist2_orient_from_stem1(stem1, twist1, u_v_t)[source]

Calculate the position of the twist factor of the 2nd stem from its parameters and the first stem.

Parameters:
  • stem1 – The vector representing the axis of stem1’s cylinder
  • twist1 – The twist factor of stem1.
  • u_v_t – The parameters describing how the twist of stem2 is oriented with respect to stem1. A triple (u, v, t)
forgi.threedee.utilities.graph_pdb.twist2_orient_from_stem1_1(stem1_basis, u_v_t)[source]

Calculate the position of the twist factor of the 2nd stem from its parameters and the first stem.

Parameters:
  • stem1 – The vector representing the axis of stem1’s cylinder
  • twist1 – The twist factor of stem1.
  • u_v_t – The parameters describing how the twist of stem2 is oriented with respect to stem1. A triple (u, v, t)
forgi.threedee.utilities.graph_pdb.verify_vatom_positions(residue_ids, chains, coords, twists, label='')[source]
Parameters:coords – The coords of ONE stem
forgi.threedee.utilities.graph_pdb.virtual_atoms(cg, given_atom_names=None, sidechain=True)[source]

Get a list of virtual atoms for this structure.

Parameters:cg – The coarse grain structure.
forgi.threedee.utilities.graph_pdb.virtual_res_3d_pos(bg, stem, i, stem_inv=None, stem_length=None)[source]
forgi.threedee.utilities.graph_pdb.virtual_res_3d_pos_core(coords, twists, i, stem_len, stem_inv=None)[source]

Calculate the virtual position of the i’th nucleotide in the stem.

The virtual position extrapolates the position of the residues based on the twists of the helix.

Returns:A tuple containing the point located on the axis of the stem and a vector away from that point in the direction of the residue.
forgi.threedee.utilities.graph_pdb.virtual_res_basis(bg, stem, i, vec=None)[source]
forgi.threedee.utilities.graph_pdb.virtual_res_basis_core(coords, twists, i, stem_len, vec=None)[source]

Define a basis based on the location of a virtual stem residue.

The basis will be defined by the direction of the stem, the direction of the virtual residue.

Parameters:
  • bg – The BulgeGraph structure
  • stem – The name of the stem
  • i – The i’th residue of the stem
Returns:

A 3x3 matrix defining the coordinate system above.

forgi.threedee.utilities.graph_pdb.virtual_residue_atoms(bg, s, i, strand=0)[source]

Return the atoms for the virtual residue.

Parameters:
  • bg – The BulgeGraph
  • s – The stem
  • i – The virtual residue number
  • strand – The strand for which to get the virtual atoms
forgi.threedee.utilities.graph_pdb.vres_to_global_coordinates(vres_pos, vres_basis, positions)[source]

«  forgi.threedee.utilities package   ::   Contents   ::   forgi.threedee.utilities.mcannotate module  »