code
stringlengths
52
7.75k
docs
stringlengths
1
5.85k
def start_optimisation(self, rounds, temp=298.15): self._generate_initial_model() self._mmc_loop(rounds, temp=temp) return
Begin the optimisation run. Parameters ---------- rounds : int The number of rounds of optimisation to perform. temp : float, optional The temperature (in K) used during the optimisation.
def _generate_initial_model(self): initial_parameters = [p.current_value for p in self.current_parameters] try: initial_model = self.specification(*initial_parameters) except TypeError: raise TypeError( 'Failed to build initial model. Make sure th...
Creates the initial model for the optimistation. Raises ------ TypeError Raised if the model failed to build. This could be due to parameters being passed to the specification in the wrong format.
def _initialize_pop(self, pop_size): self.toolbox.register("individual", self._generate) self.toolbox.register("population", tools.initRepeat, list, self.toolbox.individual) self.population = self.toolbox.population(n=pop_size) if self.neighbours: ...
Assigns indices to individuals in population.
def _crossover(self, ind): if self.neighbours: a, b, c = random.sample([self.population[i] for i in ind.neighbours], 3) else: a, b, c = random.sample(self.population, 3) y = self.toolbox.clone(a) y.ident = ind.ident ...
Used by the evolution process to generate a new individual. Notes ----- This is a tweaked version of the classical DE crossover algorithm, the main difference that candidate parameters are generated using a lognormal distribution. Bound handling is achieved by resampling...
def _update_pop(self, pop_size): candidates = [] for ind in self.population: candidates.append(self._crossover(ind)) self._model_count += len(candidates) self.assign_fitnesses(candidates) for i in range(len(self.population)): if candidates[i].fitn...
Updates population according to crossover and fitness criteria.
def _generate(self): part = creator.Particle( [random.uniform(-1, 1) for _ in range(len(self.value_means))]) part.speed = [ random.uniform(-self.max_speed, self.max_speed) for _ in range(len(self.value_means))] part.smin = -self.max_speed...
Generates a particle using the creator function. Notes ----- Position and speed are uniformly randomly seeded within allowed bounds. The particle also has speed limit settings taken from global values. Returns ------- part : particle object A...
def update_particle(self, part, chi=0.729843788, c=2.05): neighbour_pool = [self.population[i] for i in part.neighbours] best_neighbour = max(neighbour_pool, key=lambda x: x.best.fitness) ce1 = (c * random.uniform(0, 1) for _ in range(len(part))) ce2 = (c * random.uniform(0, 1) ...
Constriction factor update particle method. Notes ----- Looks for a list of neighbours attached to a particle and uses the particle's best position and that of the best neighbour.
def _update_pop(self, pop_size): valid_particles = [] invalid_particles = [] for part in self.population: if any(x > 1 or x < -1 for x in part): invalid_particles.append(part) else: valid_particles.append(part) self._model_...
Assigns fitnesses to particles that are within bounds.
def _initialize_pop(self, pop_size): self.toolbox.register("individual", self._generate) self.toolbox.register("population", tools.initRepeat, list, self.toolbox.individual) self.population = self.toolbox.population(n=pop_size) self.assign_fitnesses...
Assigns indices to individuals in population.
def _update_pop(self, pop_size): offspring = list(map(self.toolbox.clone, self.population)) for _ in range(pop_size // 2): if random.random() < self.cxpb: child1, child2 = self.toolbox.select(self.population, 2, 6) temp1 = self.toolbox.clone(child1) ...
Updates population according to crossover and fitness criteria.
def _initialize_pop(self, pop_size): self.initialize_cma_es(pop_size) self.toolbox.register("individual", self._make_individual) self.toolbox.register("generate", self._generate, self.toolbox.individual) self.toolbox.register("population", tools.ini...
Generates the initial population and assigns fitnesses.
def _initial_individual(self): ind = creator.Individual( [random.uniform(-1, 1) for _ in range(len(self.value_means))]) return ind
Generates an individual with random parameters within bounds.
def _update_pop(self, pop_size): self.toolbox.generate() # simple bound checking for i in range(len(self.population)): for j in range(len(self.population[i])): if self.population[i][j] > 1: self.population[i][j] = 1 if self...
Updates population according to crossover and fitness criteria.
def _make_individual(self, paramlist): part = creator.Individual(paramlist) part.ident = None return part
Makes an individual particle.
def initialize_cma_es(self, lambda_): # Create a centroid as a numpy array self.centroid = numpy.array([0] * len(self.value_means)) self.dim = len(self.centroid) self.pc = numpy.zeros(self.dim) self.ps = numpy.zeros(self.dim) self.chiN = numpy.sqrt(self.dim) * (...
A strategy that will keep track of the basic parameters. Parameters ---------- centroid: An iterable object that indicates where to start the evolution. parameter: One or more parameter to pass to the strategy as described in the following...
def _generate(self, func): arz = numpy.random.standard_normal((self.lambda_, self.dim)) arz = self.centroid + self.sigma * numpy.dot(arz, self.BD.T) self.population = list(map(func, arz)) return
Generate a population of :math:`\lambda` individuals. Notes ----- Individuals are of type *ind_init* from the current strategy. Parameters ---------- ind_init: A function object that is able to initialize an individual from a list.
def number_of_mmols(code): # If num_mmols is already known, return it if mmols_numbers: if code in mmols_numbers.keys(): mmol = mmols_numbers[code][0] return mmol counter = 1 while True: pdbe_url = "http://www.ebi.ac.uk/pdbe/static/entry/download/{0}-assembly...
Number of .mmol files associated with code in the PDBE. Notes ----- This function makes a series of calls to the PDBE website using the requests module. This can make it slow! Parameters ---------- code : str PDB code. Returns ------- num_mmols : int Raises ------...
def get_cif(code, mmol_number, outfile=None): pdbe_url = "http://www.ebi.ac.uk/pdbe/static/entry/download/{0}-assembly-{1}.cif.gz".format(code, mmol_number) r = requests.get(pdbe_url) if r.status_code == 200: temp_gz = tempfile.NamedTemporaryFile() temp_gz.write(r.content) with ...
Parameters ---------- code : str PDB code. mmol_number : int mmol number (biological assembly number) of file to download. Numbers from PDBe. If None, defaults to the preferred biological assembly listed for code on the PDBe. outfile : str Filepath. Writes returned value ...
def get_mmcif(code, outfile=None): pdbe_url = "http://www.ebi.ac.uk/pdbe/entry-files/download/{0}.cif".format(code) r = requests.get(pdbe_url) if r.status_code == 200: mmcif_string = r.text else: print("Could not download mmcif file for {0}".format(code)) mmcif_string = None...
Get mmcif file associated with code from PDBE. Parameters ---------- code : str PDB code. outfile : str Filepath. Writes returned value to this file. Returns ------- mmcif_file : str Filepath to the mmcif file.
def pdbe_status_code(code): url = 'http://www.ebi.ac.uk/pdbe/entry-files/download/{0}_1.mmol'.format(code) r = requests.head(url=url) return r.status_code
Check if a PDB code has structure files on the PDBE site. Parameters ---------- code : str PDB code to check for on PDBE. Returns ------- status_code : int HTTP status code of PDBE url associated with input code.
def current_codes_from_pdb(): url = 'http://www.rcsb.org/pdb/rest/getCurrent' r = requests.get(url) if r.status_code == 200: pdb_codes = [x.lower() for x in r.text.split('"') if len(x) == 4] else: print('Request for {0} failed with status code {1}'.format(url, r.status_code)) ...
Get list of all PDB codes currently listed in the PDB. Returns ------- pdb_codes : list(str) List of PDB codes (in lower case).
def local_pdb_codes(data_dir=None): if not data_dir: data_dir = global_settings["structural_database"]["path"] p = Path(data_dir) pdb_parent_dirs = [x for x in p.iterdir() if x.is_dir() and len(x.parts[-1]) == 2] pdb_folders = [x for test in pdb_parent_dirs for x in test.iterdir() if x.is_d...
Get list of PDB codes stored in a folder (FileSystem folder hierarchy expected within data_dir). If no folder is specified, use the database_dir defined in settings.json. Parameters ---------- data_dir: str Filepath to a folder containing the PDB folder hierarchy (eg data_dir/eb/2ebo) Ret...
def make_code_obsolete(code): fs = FileSystem(code=code) if os.path.exists(fs.parent_dir): # Move to obsolete folder destination_dir = os.path.join(fs._data_dir, 'obsolete', code[1:3], code) if os.path.exists(destination_dir): shutil.rmtree(destination_dir) shuti...
Moves folders associated with PDB code to obsolete folder in global_settings["database_dir"] Parameters ---------- code : str PDB accession code Returns ------- None
def mmols(self): mmols_dict = {} mmol_dir = os.path.join(self.parent_dir, 'structures') if not os.path.exists(mmol_dir): os.makedirs(mmol_dir) mmol_file_names = ['{0}_{1}.mmol'.format(self.code, i) for i in range(1, self.number_of_mmols + 1)] mmol_files = [os...
Dict of filepaths for all mmol files associated with code. Notes ----- Downloads mmol files if not already present. Returns ------- mmols_dict : dict, or None. Keys : int mmol number Values : str Filepath for the c...
def dssps(self): dssps_dict = {} dssp_dir = os.path.join(self.parent_dir, 'dssp') if not os.path.exists(dssp_dir): os.makedirs(dssp_dir) for i, mmol_file in self.mmols.items(): dssp_file_name = '{0}.dssp'.format(os.path.basename(mmol_file)) ds...
Dict of filepaths for all dssp files associated with code. Notes ----- Runs dssp and stores writes output to files if not already present. Also downloads mmol files if not already present. Calls isambard.external_programs.dssp and so needs dssp to be installed. Returns ...
def fastas(self, download=False): fastas_dict = {} fasta_dir = os.path.join(self.parent_dir, 'fasta') if not os.path.exists(fasta_dir): os.makedirs(fasta_dir) for i, mmol_file in self.mmols.items(): mmol_name = os.path.basename(mmol_file) fast...
Dict of filepaths for all fasta files associated with code. Parameters ---------- download : bool If True, downloads the fasta file from the PDB. If False, uses the ampal Protein.fasta property Defaults to False - this is definitely the recommended behaviour....
def mmcif(self): mmcif_dir = os.path.join(self.parent_dir, 'mmcif') if not os.path.exists(mmcif_dir): os.makedirs(mmcif_dir) mmcif_file_name = '{0}.cif'.format(self.code) mmcif_file = os.path.join(mmcif_dir, mmcif_file_name) if not os.path.exists(mmcif_file):...
Filepath for mmcif file associated with code. Notes ----- Downloads mmcif file if not already present. Returns ------- mmcif_file : str Filepath for the mmcif file.
def categories(self): category_dict = {} for ligand in self: if ligand.category in category_dict: category_dict[ligand.category].append(ligand) else: category_dict[ligand.category] = [ligand] return category_dict
Returns the categories of `Ligands` in `LigandGroup`.
def category_count(self): category_dict = self.categories count_dict = {category: len( category_dict[category]) for category in category_dict} return count_dict
Returns the number of categories in `categories`.
def sequence_molecular_weight(seq): if 'X' in seq: warnings.warn(_nc_warning_str, NoncanonicalWarning) return sum( [residue_mwt[aa] * n for aa, n in Counter(seq).items()]) + water_mass
Returns the molecular weight of the polypeptide sequence. Notes ----- Units = Daltons Parameters ---------- seq : str Sequence of amino acids.
def sequence_molar_extinction_280(seq): if 'X' in seq: warnings.warn(_nc_warning_str, NoncanonicalWarning) return sum([residue_ext_280[aa] * n for aa, n in Counter(seq).items()])
Returns the molar extinction coefficient of the sequence at 280 nm. Notes ----- Units = M/cm Parameters ---------- seq : str Sequence of amino acids.
def partial_charge(aa, pH): difference = pH - residue_pka[aa] if residue_charge[aa] > 0: difference *= -1 ratio = (10 ** difference) / (1 + 10 ** difference) return ratio
Calculates the partial charge of the amino acid. Parameters ---------- aa : str Amino acid single-letter code. pH : float pH of interest.
def sequence_charge(seq, pH=7.4): if 'X' in seq: warnings.warn(_nc_warning_str, NoncanonicalWarning) adj_protein_charge = sum( [partial_charge(aa, pH) * residue_charge[aa] * n for aa, n in Counter(seq).items()]) adj_protein_charge += ( partial_charge('N-term', pH) * res...
Calculates the total charge of the input polypeptide sequence. Parameters ---------- seq : str Sequence of amino acids. pH : float pH of interest.
def charge_series(seq, granularity=0.1): if 'X' in seq: warnings.warn(_nc_warning_str, NoncanonicalWarning) ph_range = numpy.arange(1, 13, granularity) charge_at_ph = [sequence_charge(seq, ph) for ph in ph_range] return ph_range, charge_at_ph
Calculates the charge for pH 1-13. Parameters ---------- seq : str Sequence of amino acids. granularity : float, optional Granularity of pH values i.e. if 0.1 pH = [1.0, 1.1, 1.2...]
def sequence_isoelectric_point(seq, granularity=0.1): if 'X' in seq: warnings.warn(_nc_warning_str, NoncanonicalWarning) ph_range, charge_at_ph = charge_series(seq, granularity) abs_charge_at_ph = [abs(ch) for ch in charge_at_ph] pi_index = min(enumerate(abs_charge_at_ph), key=lambda x: x[1...
Calculates the isoelectric point of the sequence for ph 1-13. Parameters ---------- seq : str Sequence of amino acids. granularity : float, optional Granularity of pH values i.e. if 0.1 pH = [1.0, 1.1, 1.2...]
def measure_sidechain_torsion_angles(residue, verbose=True): chi_angles = [] aa = residue.mol_code if aa not in side_chain_dihedrals: if verbose: print("Amino acid {} has no known side-chain dihedral".format(aa)) else: for set_atoms in side_chain_dihedrals[aa]: ...
Calculates sidechain dihedral angles for a residue Parameters ---------- residue : [ampal.Residue] `Residue` object. verbose : bool, optional If `true`, tells you when a residue does not have any known dihedral angles to measure. Returns ------- chi_angles: [float] ...
def cc_to_local_params(pitch, radius, oligo): rloc = numpy.sin(numpy.pi / oligo) * radius alpha = numpy.arctan((2 * numpy.pi * radius) / pitch) alphaloc = numpy.cos((numpy.pi / 2) - ((numpy.pi) / oligo)) * alpha pitchloc = (2 * numpy.pi * rloc) / numpy.tan(alphaloc) return pitchloc, rloc, numpy...
Returns local parameters for an oligomeric assembly. Parameters ---------- pitch : float Pitch of assembly radius : float Radius of assembly oligo : int Oligomeric state of assembly Returns ------- pitchloc : float Local pitch of assembly (between 2 adja...
def residues_per_turn(p): cas = p.get_reference_coords() prim_cas = p.primitive.coordinates dhs = [abs(dihedral(cas[i], prim_cas[i], prim_cas[i + 1], cas[i + 1])) for i in range(len(prim_cas) - 1)] rpts = [360.0 / dh for dh in dhs] rpts.append(None) return rpts
The number of residues per turn at each Monomer in the Polymer. Notes ----- Each element of the returned list is the number of residues per turn, at a point on the Polymer primitive. Calculated using the relative positions of the CA atoms and the primitive of the Polymer. Element i is the calcu...
def crick_angles(p, reference_axis, tag=True, reference_axis_name='ref_axis'): if not len(p) == len(reference_axis): raise ValueError( "The reference axis must contain the same number of points" " as the Polymer primitive.") prim_cas = p.primitive.coordinates p_cas = p.g...
Returns the Crick angle for each CA atom in the `Polymer`. Notes ----- The final value is in the returned list is `None`, since the angle calculation requires pairs of points on both the primitive and reference_axis. Parameters ---------- p : ampal.Polymer Reference `Polymer`. ...
def alpha_angles(p, reference_axis, tag=True, reference_axis_name='ref_axis'): if not len(p) == len(reference_axis): raise ValueError( "The reference axis must contain the same number of points " "as the Polymer primitive.") prim_cas = p.primitive.coordinates ref_points ...
Alpha angle calculated using points on the primitive of helix and axis. Notes ----- The final value is None, since the angle calculation requires pairs of points along the primitive and axis. This is a generalisation of the calculation used to measure the tilt of a helix in a coiled-coil with r...
def polypeptide_vector(p, start_index=0, end_index=-1, unit=True): if len(p) <= 1: raise ValueError( "Polymer should have length greater than 1. Polymer length = {0}".format(len(p))) try: prim_cas = p.primitive.coordinates direction_vector = prim_cas[end_index] - prim_ca...
Vector along the Chain primitive (default is from N-terminus to C-terminus). Notes ----- `start_index` and `end_index` can be changed to examine smaller sections of the Chain, or reversed to change the direction of the vector. Parameters ---------- p : ampal.Polymer Reference `...
def reference_axis_from_chains(chains): if not len(set([len(x) for x in chains])) == 1: raise ValueError("All chains must be of the same length") # First array in coords is the primitive coordinates of the first chain. # The orientation of the first chain orients the reference_axis. coords...
Average coordinates from a set of primitives calculated from Chains. Parameters ---------- chains : list(Chain) Returns ------- reference_axis : numpy.array The averaged (x, y, z) coordinates of the primitives for the list of Chains. In the case of a coiled coil barrel, ...
def flip_reference_axis_if_antiparallel( p, reference_axis, start_index=0, end_index=-1): p_vector = polypeptide_vector( p, start_index=start_index, end_index=end_index) if is_acute(p_vector, reference_axis[end_index] - reference_axis[start_index]): reference_axis = ...
Flips reference axis if direction opposes the direction of the `Polymer`. Notes ----- If the angle between the vector for the Polymer and the vector for the reference_axis is > 90 degrees, then the reference axis is reversed. This is useful to run before running polymer_to_reference_axis_distan...
def make_primitive(cas_coords, window_length=3): if len(cas_coords) >= window_length: primitive = [] count = 0 for _ in cas_coords[:-(window_length - 1)]: group = cas_coords[count:count + window_length] average_x = sum([x[0] for x in group]) / window_length ...
Calculates running average of cas_coords with a fixed averaging window_length. Parameters ---------- cas_coords : list(numpy.array or float or tuple) Each element of the list must have length 3. window_length : int, optional The number of coordinate sets to average each time. Retur...
def make_primitive_smoothed(cas_coords, smoothing_level=2): try: s_primitive = make_primitive(cas_coords) for x in range(smoothing_level): s_primitive = make_primitive(s_primitive) except ValueError: raise ValueError( 'Smoothing level {0} too high, try reduci...
Generates smoothed primitive from a list of coordinates. Parameters ---------- cas_coords : list(numpy.array or float or tuple) Each element of the list must have length 3. smoothing_level : int, optional Number of times to run the averaging. Returns ------- s_primitive : l...
def extend(self, ampal_container): if isinstance(ampal_container, AmpalContainer): self._ampal_objects.extend(ampal_container) else: raise TypeError( 'Only AmpalContainer objects may be merged with ' 'an AmpalContainer.') return
Extends an `AmpalContainer` with another `AmpalContainer`.
def pdb(self): header_title = '{:<80}\n'.format('HEADER {}'.format(self.id)) data_type = '{:<80}\n'.format('EXPDTA ISAMBARD Model') pdb_strs = [] for ampal in self: if isinstance(ampal, Assembly): pdb_str = ampal.make_pdb(header=False, footer=Fa...
Compiles the PDB strings for each state into a single file.
def sort_by_tag(self, tag): return AmpalContainer(sorted(self, key=lambda x: x.tags[tag]))
Sorts the `AmpalContainer` by a tag on the component objects. Parameters ---------- tag : str Key of tag used for sorting.
def append(self, item): if isinstance(item, Polymer): self._molecules.append(item) else: raise TypeError( 'Only Polymer objects can be appended to an Assembly.') return
Adds a `Polymer` to the `Assembly`. Raises ------ TypeError Raised if other is any type other than `Polymer`.
def extend(self, assembly): if isinstance(assembly, Assembly): self._molecules.extend(assembly) else: raise TypeError( 'Only Assembly objects may be merged with an Assembly.') return
Extends the `Assembly` with the contents of another `Assembly`. Raises ------ TypeError Raised if other is any type other than `Assembly`.
def get_monomers(self, ligands=True, pseudo_group=False): base_filters = dict(ligands=ligands, pseudo_group=pseudo_group) restricted_mol_types = [x[0] for x in base_filters.items() if not x[1]] in_groups = [x for x in self.filter_mol_types(restricted_mol_types)] monomers = itert...
Retrieves all the `Monomers` from the `Assembly` object. Parameters ---------- ligands : bool, optional If `true`, will include ligand `Monomers`. pseudo_group : bool, optional If `True`, will include pseudo atoms.
def get_ligands(self, solvent=True): if solvent: ligand_list = [x for x in self.get_monomers() if isinstance(x, Ligand)] else: ligand_list = [x for x in self.get_monomers() if isinstance( x, Ligand) and not x.is_solvent] ...
Retrieves all ligands from the `Assembly`. Parameters ---------- solvent : bool, optional If `True`, solvent molecules will be included.
def get_atoms(self, ligands=True, pseudo_group=False, inc_alt_states=False): atoms = itertools.chain( *(list(m.get_atoms(inc_alt_states=inc_alt_states)) for m in self.get_monomers(ligands=ligands, pseudo_group=pseudo_group))) ...
Flat list of all the `Atoms` in the `Assembly`. Parameters ---------- ligands : bool, optional Include ligand `Atoms`. pseudo_group : bool, optional Include pseudo_group `Atoms`. inc_alt_states : bool, optional Include alternate sidechain conf...
def is_within(self, cutoff_dist, point, ligands=True): return find_atoms_within_distance(self.get_atoms(ligands=ligands), cutoff_dist, point)
Returns all atoms in AMPAL object within `cut-off` distance from the `point`.
def relabel_polymers(self, labels=None): if labels: if len(self._molecules) == len(labels): for polymer, label in zip(self._molecules, labels): polymer.id = label else: raise ValueError('Number of polymers ({}) and number of la...
Relabels the component Polymers either in alphabetical order or using a list of labels. Parameters ---------- labels : list, optional A list of new labels. Raises ------ ValueError Raised if the number of labels does not match the number of compo...
def relabel_atoms(self, start=1): counter = start for atom in self.get_atoms(ligands=True): atom.id = counter counter += 1 return
Relabels all Atoms in numerical order, offset by the start parameter. Parameters ---------- start : int, optional Defines an offset for the labelling.
def make_pdb(self, ligands=True, alt_states=False, pseudo_group=False, header=True, footer=True): base_filters = dict(ligands=ligands, pseudo_group=pseudo_group) restricted_mol_types = [x[0] for x in base_filters.items() if not x[1]] in_groups = [x for x in self.filter_mol_types(restric...
Generates a PDB string for the Assembly. Parameters ---------- ligands : bool, optional If `True`, will include ligands in the output. alt_states : bool, optional If `True`, will include alternate conformations in the output. pseudo_group : bool, optional...
def backbone(self): bb_molecules = [ p.backbone for p in self._molecules if hasattr(p, 'backbone')] bb_assembly = Assembly(bb_molecules, assembly_id=self.id) return bb_assembly
Generates a new `Assembly` containing only the backbone atoms. Notes ----- Metadata is not currently preserved from the parent object. Sequence data is retained, but only the main chain atoms are retained. Returns ------- bb_assembly : ampal.Protein ...
def primitives(self): prim_molecules = [ p.primitive for p in self._molecules if hasattr(p, 'primitive')] prim_assembly = Assembly(molecules=prim_molecules, assembly_id=self.id) return prim_assembly
Generates a new `Assembly` containing the primitives of each Polymer. Notes ----- Metadata is not currently preserved from the parent object. Returns ------- prim_assembly : ampal.Protein `Assembly` containing only the primitives of the `Polymers` ...
def helices(self): hel_molecules = list(itertools.chain( *[p.helices._molecules for p in self._molecules if hasattr(p, 'helices')])) hel_assembly = Assembly(molecules=hel_molecules, assembly_id=self.id) return hel_assembly
Generates new `Assembly` containing just α-helices. Notes ----- Metadata is not currently preserved from the parent object. Returns ------- hel_assembly : ampal.Protein `Assembly` containing only the α-helices of the original `Assembly`.
def strands(self): strand_molecules = list(itertools.chain( *[p.strands._molecules for p in self._molecules if hasattr(p, 'strands')])) strand_assembly = Assembly( molecules=strand_molecules, assembly_id=self.id) return strand_assembly
Generates a new `Assembly` containing only the β-strands. Notes ----- Metadata is not currently preserved from the parent object. Returns ------- strand_assembly : ampal.Protein `Assembly` containing only the β-strands of the original `Assembly`.
def sequences(self): seqs = [x.sequence for x in self._molecules if hasattr(x, 'sequence')] return seqs
Returns the sequence of each `Polymer` in the `Assembly` as a list. Returns ------- sequences : [str] List of sequences.
def fasta(self): fasta_str = '' max_line_length = 79 for p in self._molecules: if hasattr(p, 'sequence'): fasta_str += '>{0}:{1}|PDBID|CHAIN|SEQUENCE\n'.format( self.id.upper(), p.id) seq = p.sequence split_...
Generates a FASTA string for the `Assembly`. Notes ----- Explanation of FASTA format: https://en.wikipedia.org/wiki/FASTA_format Recommendation that all lines of text be shorter than 80 characters is adhered to. Format of PDBID|CHAIN|SEQUENCE is consistent with files do...
def get_interaction_energy(self, assign_ff=True, ff=None, mol2=False, force_ff_assign=False): if not ff: ff = global_settings['buff']['force_field'] if assign_ff: for molecule in self._molecules: if hasattr(molecule, 'update...
Calculates the interaction energy of the AMPAL object. Parameters ---------- assign_ff: bool, optional If true the force field will be updated if required. ff: BuffForceField, optional The force field to be used for scoring. mol2: bool, optional ...
def repack_all(self): non_na_sequences = [s for s in self.sequences if ' ' not in s] self.pack_new_sequences(non_na_sequences) return
Repacks the side chains of all Polymers in the Assembly.
def tag_secondary_structure(self, force=False): for polymer in self._molecules: if polymer.molecule_type == 'protein': polymer.tag_secondary_structure(force=force) return
Tags each `Monomer` in the `Assembly` with it's secondary structure. Notes ----- DSSP must be available to call. Check by running `isambard.external_programs.dssp.test_dssp`. If DSSP is not available, please follow instruction here to add it: https://github.com/woolfson-...
def tag_dssp_solvent_accessibility(self, force=False): for polymer in self._molecules: polymer.tag_dssp_solvent_accessibility(force=force) return
Tags each `Monomer` in the Assembly with its solvent accessibility. Notes ----- For more about DSSP's solvent accessibilty metric, see: http://swift.cmbi.ru.nl/gv/dssp/HTML/descrip.html#ACC DSSP must be available to call. Check by running `isambard.external_programs...
def tag_torsion_angles(self, force=False): for polymer in self._molecules: if polymer.molecule_type == 'protein': polymer.tag_torsion_angles(force=force) return
Tags each `Monomer` in the `Assembly` with its torsion angles. Parameters ---------- force : bool, optional If `True`, the tag will be run even if `Monomers` are already tagged.
def tag_ca_geometry(self, force=False, reference_axis=None, reference_axis_name='ref_axis'): for polymer in self._molecules: if polymer.molecule_type == 'protein': polymer.tag_ca_geometry( force=force, reference_axis=reference_axis...
Tags each `Monomer` in the `Assembly` with its helical geometry. Parameters ---------- force : bool, optional If True the tag will be run even if `Monomers` are already tagged. reference_axis : list(numpy.array or tuple or list), optional Coordinates to feed to g...
def tag_atoms_unique_ids(self, force=False): tagged = ['unique_id' in x.tags.keys() for x in self.get_atoms()] if (not all(tagged)) or force: for m in self.get_monomers(): for atom_type, atom in m.atoms.items(): atom.tags['unique_id'] = (m.unique_...
Tags each Atom in the Assembly with its unique_id. Notes ----- The unique_id for each atom is a tuple (a double). `unique_id[0]` is the unique_id for its parent `Monomer` (see `Monomer.unique_id` for more information). `unique_id[1]` is the atom_type in the `Assembly` as...
def align_nab(tar, ref): rot_trans_1 = find_transformations( tar['N'].array, tar['CA'].array, ref['N'].array, ref['CA'].array) apply_trans_rot(tar, *rot_trans_1) rot_ang_ca_cb = dihedral(tar['CB'], ref['CA'], ref['N'], ref['CB']) tar.rotate(rot_ang_ca_cb, ref['N'].array - ref['CA'].array, r...
Aligns the N-CA and CA-CB vector of the target monomer. Parameters ---------- tar: ampal.Residue The residue that will be aligned to the reference. ref: ampal.Residue The reference residue for the alignment.
def apply_trans_rot(ampal, translation, angle, axis, point, radians=False): if not numpy.isclose(angle, 0.0): ampal.rotate(angle=angle, axis=axis, point=point, radians=radians) ampal.translate(vector=translation) return
Applies a translation and rotation to an AMPAL object.
def find_ss_regions_polymer(polymer, ss): if isinstance(ss, str): ss = [ss[:]] tag_key = 'secondary_structure' monomers = [x for x in polymer if tag_key in x.tags.keys()] if len(monomers) == 0: return Assembly() if (len(ss) == 1) and (all([m.tags[tag_key] == ss[0] for m in monom...
Returns an `Assembly` of regions tagged as secondary structure. Parameters ---------- polymer : Polypeptide `Polymer` object to be searched secondary structure regions. ss : list List of secondary structure tags to be separate i.e. ['H'] would return helices, ['H', 'E'] would re...
def flat_list_to_polymer(atom_list, atom_group_s=4): atom_labels = ['N', 'CA', 'C', 'O', 'CB'] atom_elements = ['N', 'C', 'C', 'O', 'C'] atoms_coords = [atom_list[x:x + atom_group_s] for x in range(0, len(atom_list), atom_group_s)] atoms = [[Atom(x[0], x[1]) for x in zip(y, atom...
Takes a flat list of atomic coordinates and converts it to a `Polymer`. Parameters ---------- atom_list : [Atom] Flat list of coordinates. atom_group_s : int, optional Size of atom groups. Returns ------- polymer : Polypeptide `Polymer` object containing atom coords...
def align(target, mobile, target_i=0, mobile_i=0): # First, align N->CA vectors. s1, e1, s2, e2 = [x._vector for x in [mobile[mobile_i]['N'], mobile[mobile_i]['CA'], target[target_i]['N'], target[target_i]['CA']]] translation, angle, axis, point = f...
Aligns one Polypeptide (mobile) to another (target). Notes ----- This function directly modifies atoms of the mobile Polypeptide! It does not return a new object. Parameters ---------- target : Polypeptide Polypeptide to be aligned to. mobile : Polypeptide Polypeptide t...
def get_slice_from_res_id(self, start, end): id_dict = {str(m.id): m for m in self._monomers} slice_polymer = Polypeptide( [id_dict[str(x)] for x in range(int(start), int(end) + 1)], self.id) return slice_polymer
Returns a new `Polypeptide` containing the `Residues` in start/end range. Parameters ---------- start : str string representing start residue id (PDB numbering) end : str string representing end residue id (PDB numbering) Returns ------- ...
def backbone(self): bb_poly = Polypeptide([x.backbone for x in self._monomers], self.id) return bb_poly
Returns a new `Polymer` containing only the backbone atoms. Notes ----- Metadata is not currently preserved from the parent object. Sequence data is retained, but only the main chain atoms are retained. Returns ------- bb_poly : Polypeptide Polymer c...
def pack_new_sequence(self, sequence): # This import is here to prevent a circular import. from ampal.pdb_parser import convert_pdb_to_ampal polymer_bb = self.backbone if len(sequence) != len(polymer_bb): raise ValueError( 'Sequence length ({}) does n...
Packs a new sequence onto the polymer using Scwrl4. Parameters ---------- sequence : str String containing the amino acid sequence. This must be the same length as the Polymer Raises ------ ValueError Raised if the sequence length doe...
def sequence(self): seq = [x.mol_letter for x in self._monomers] return ''.join(seq)
Returns the sequence of the `Polymer` as a string. Returns ------- sequence : str String of the `Residue` sequence of the `Polypeptide`.
def backbone_bond_lengths(self): bond_lengths = dict( n_ca=[distance(r['N'], r['CA']) for r in self.get_monomers(ligands=False)], ca_c=[distance(r['CA'], r['C']) for r in self.get_monomers(ligands=False)], c_o=[distance(r['C'], r['...
Dictionary containing backbone bond lengths as lists of floats. Returns ------- bond_lengths : dict Keys are `n_ca`, `ca_c`, `c_o` and `c_n`, referring to the N-CA, CA-C, C=O and C-N bonds respectively. Values are lists of floats : the bond lengths in Angstro...
def backbone_bond_angles(self): bond_angles = dict( n_ca_c=[angle_between_vectors(r['N'] - r['CA'], r['C'] - r['CA']) for r in self.get_monomers(ligands=False)], ca_c_o=[angle_between_vectors(r['CA'] - r['C'], r['O'] - r['C']) for r in sel...
Dictionary containing backbone bond angles as lists of floats. Returns ------- bond_angles : dict Keys are `n_ca_c`, `ca_c_o`, `ca_c_n` and `c_n_ca`, referring to the N-CA-C, CA-C=O, CA-C-N and C-N-CA angles respectively. Values are lists of floats : the bond...
def tag_secondary_structure(self, force=False): tagged = ['secondary_structure' in x.tags.keys() for x in self._monomers] if (not all(tagged)) or force: dssp_out = run_dssp(self.pdb, path=False) if dssp_out is None: return ds...
Tags each `Residue` of the `Polypeptide` with secondary structure. Notes ----- DSSP must be available to call. Check by running `isambard.external_programs.dssp.test_dssp`. If DSSP is not available, please follow instruction here to add it: https://github.com/woolfson-gr...
def tag_dssp_solvent_accessibility(self, force=False): tagged = ['dssp_acc' in x.tags.keys() for x in self._monomers] if (not all(tagged)) or force: dssp_out = run_dssp(self.pdb, path=False) if dssp_out is None: return dssp_acc_list = extract_...
Tags each `Residues` Polymer with its solvent accessibility. Notes ----- For more about DSSP's solvent accessibilty metric, see: http://swift.cmbi.ru.nl/gv/dssp/HTML/descrip.html#ACC References ---------- .. [1] Kabsch W, Sander C (1983) "Dictionary of prote...
def tag_sidechain_dihedrals(self, force=False): tagged = ['chi_angles' in x.tags.keys() for x in self._monomers] if (not all(tagged)) or force: for monomer in self._monomers: chi_angles = measure_sidechain_torsion_angles( monomer, verbose=False) ...
Tags each monomer with side-chain dihedral angles force: bool, optional If `True` the tag will be run even if `Residues` are already tagged.
def tag_torsion_angles(self, force=False): tagged = ['omega' in x.tags.keys() for x in self._monomers] if (not all(tagged)) or force: tas = measure_torsion_angles(self._monomers) for monomer, (omega, phi, psi) in zip(self._monomers, tas): monomer.tags['om...
Tags each Monomer of the Polymer with its omega, phi and psi torsion angle. Parameters ---------- force : bool, optional If `True` the tag will be run even if `Residues` are already tagged.
def tag_ca_geometry(self, force=False, reference_axis=None, reference_axis_name='ref_axis'): tagged = ['rise_per_residue' in x.tags.keys() for x in self._monomers] if (not all(tagged)) or force: # Assign tags None if Polymer is too short to have a primitive. ...
Tags each `Residue` with rise_per_residue, radius_of_curvature and residues_per_turn. Parameters ---------- force : bool, optional If `True` the tag will be run even if `Residues` are already tagged. reference_axis : list(numpy.array or tuple or list), optional ...
def valid_backbone_bond_lengths(self, atol=0.1): bond_lengths = self.backbone_bond_lengths a1 = numpy.allclose(bond_lengths['n_ca'], [ideal_backbone_bond_lengths['n_ca']] * len(self), atol=atol) a2 = numpy.allclose(bond_lengths['ca...
True if all backbone bonds are within atol Angstroms of the expected distance. Notes ----- Ideal bond lengths taken from [1]. References ---------- .. [1] Schulz, G. E, and R. Heiner Schirmer. Principles Of Protein Structure. New York: Springer-Verlag, 1979. ...
def valid_backbone_bond_angles(self, atol=20): bond_angles = self.backbone_bond_angles omegas = [x[0] for x in measure_torsion_angles(self)] trans = ['trans' if (omega is None) or ( abs(omega) >= 90) else 'cis' for omega in omegas] ideal_n_ca_c = [ideal_backbone_bond...
True if all backbone bond angles are within atol degrees of their expected values. Notes ----- Ideal bond angles taken from [1]. References ---------- .. [1] Schulz, G. E, and R. Heiner Schirmer. Principles Of Protein Structure. New York: Springer-Verlag, 197...
def backbone(self): try: backbone = OrderedDict([('N', self.atoms['N']), ('CA', self.atoms['CA']), ('C', self.atoms['C']), ('O', self.atoms['O'])]) except KeyError: ...
Returns a new `Residue` containing only the backbone atoms. Returns ------- bb_monomer : Residue `Residue` containing only the backbone atoms of the original `Monomer`. Raises ------ IndexError Raise if the `atoms` dict does not conta...
def unique_id(self): if self.is_hetero: if self.mol_code == 'HOH': hetero_flag = 'W' else: hetero_flag = 'H_{0}'.format(self.mol_code) else: hetero_flag = ' ' return self.ampal_parent.id, (hetero_flag, self.id, self.ins...
Generates a tuple that uniquely identifies a `Monomer` in an `Assembly`. Notes ----- The unique_id will uniquely identify each monomer within a polymer. If each polymer in an assembly has a distinct id, it will uniquely identify each monomer within the assembly. The het...
def side_chain(self): side_chain_atoms = [] if self.mol_code != 'GLY': covalent_bond_graph = generate_covalent_bond_graph( find_covalent_bonds(self)) try: subgraphs = generate_bond_subgraphs_from_break( covalent_bond_gr...
List of the side-chain atoms (R-group). Notes ----- Returns empty list for glycine. Returns ------- side_chain_atoms: list(`Atoms`)
def side_chain_environment(self, cutoff=4, include_neighbours=True, inter_chain=True, include_ligands=False, include_solvent=False): if self.mol_code == 'GLY': return [self] side_chain_dict = {x: {y: self.states[x][y] for...
Finds `Residues` with any atom within the cutoff distance of side-chain. Notes ----- Includes the parent residue in the list. Parameters ---------- cutoff : float, optional Maximum inter-atom distance for residue to be included. Defaults to 4. ...
def load_global_settings(): with open(settings_path, 'r') as settings_f: global global_settings settings_json = json.loads(settings_f.read()) if global_settings is None: global_settings = settings_json global_settings[u'package_path'] = package_dir else: ...
Loads settings file containing paths to dependencies and other optional configuration elements.
def build(self): for i in range(2): self._molecules.append( self.make_helix(self.aas[i], self.axis_distances[i], self.z_shifts[i], self.phis[i], self.splays[i], self.off_plane[i])) return
Builds a `HelixPair` using the defined attributes.
def make_helix(aa, axis_distance, z_shift, phi, splay, off_plane): start = numpy.array([axis_distance, 0 + z_shift, 0]) end = numpy.array([axis_distance, (aa * 1.52) + z_shift, 0]) mid = (start + end) / 2 helix = Helix.from_start_and_end(start, end, aa=aa) helix.rotate(...
Builds a helix for a given set of parameters.
def build(self): self._molecules = [] if self.handedness == 'l': handedness = -1 else: handedness = 1 rot_ang = self.rot_ang * handedness for i in range(self.num_of_repeats): dup_unit = copy.deepcopy(self.repeat_unit) z = (...
Builds a Solenoid using the defined attributes.
def from_start_and_end(cls, start, end, sequence, helix_type='b_dna', phos_3_prime=False): start = numpy.array(start) end = numpy.array(end) instance = cls(sequence, helix_type=helix_type, phos_3_prime=phos_3_prime) instance.move...
Generates a helical `Polynucleotide` that is built along an axis. Parameters ---------- start: [float, float, float] Start of the build axis. end: [float, float, float] End of build axis. sequence: str The nucleotide sequence of the nucleic ac...
def move_to(self, start, end): start = numpy.array(start) end = numpy.array(end) if numpy.allclose(start, end): raise ValueError('start and end must NOT be identical') translation, angle, axis, point = find_transformations( self.helix_start, self.helix_en...
Moves the `Polynucleotide` to lie on the `start` and `end` vector. Parameters ---------- start : 3D Vector (tuple or list or numpy.array) The coordinate of the start of the helix primitive. end : 3D Vector (tuple or list or numpy.array) The coordinate of the end ...
def fit_heptad_register(crangles): crangles = [x if x > 0 else 360 + x for x in crangles] hept_p = [x * (360.0 / 7.0) + ((360.0 / 7.0) / 2.0) for x in range(7)] ideal_crangs = [ hept_p[0], hept_p[2], hept_p[4], hept_p[6], hept_p[1], hept_p[3], hep...
Attempts to fit a heptad repeat to a set of Crick angles. Parameters ---------- crangles: [float] A list of average Crick angles for the coiled coil. Returns ------- fit_data: [(float, float, float)] Sorted list of fits for each heptad position.
def gather_layer_info(self): for i in range(len(self.cc[0])): layer_radii = [x[i].tags['distance_to_ref_axis'] for x in self.cc] self.radii_layers.append(layer_radii) layer_alpha = [x[i].tags['alpha_angle_ref_axis'] for x in self.cc] self.alpha_layers.app...
Extracts the tagged coiled-coil parameters for each layer.