def generate_sequence(N=0, spin_ids=None, spin_nums=None, spin_names=None, res_nums=None, res_names=None, mol_names=None, isotopes=None, elements=None): """Generate the sequence data from the BRMB information. @keyword N: The number of spins. @type N: int @keyword spin_ids: The list of spin IDs. @type spin_ids: list of str @keyword spin_nums: The list of spin numbers. @type spin_nums: list of int or None @keyword spin_names: The list of spin names. @type spin_names: list of str or None @keyword res_nums: The list of residue numbers. @type res_nums: list of int or None @keyword res_names: The list of residue names. @type res_names: list of str or None @keyword mol_names: The list of molecule names. @type mol_names: list of str or None @keyword isotopes: The optional list of isotope types. @type isotopes: list of str or None @keyword elements: The optional list of element types. @type elements: list of str or None """ # The blank data. if not spin_nums: spin_nums = [None] * N if not spin_names: spin_names = [None] * N if not res_nums: res_nums = [None] * N if not res_names: res_names = [None] * N if not mol_names: mol_names = [None] * N # Generate the spin IDs. spin_ids = [] for i in range(N): spin_ids.append(generate_spin_id(mol_name=mol_names[i], res_num=res_nums[i], spin_name=spin_names[i])) # Loop over the spin data. for i in range(N): # The spin already exists. spin = return_spin(spin_ids[i]) if spin: continue # Create the spin. spin = create_spin(spin_num=spin_nums[i], spin_name=spin_names[i], res_num=res_nums[i], res_name=res_names[i], mol_name=mol_names[i]) # Set the spin isotope and element. spin_id = spin._spin_ids[0] if elements: set_spin_element(spin_id=spin_id, element=elements[i], force=True) if isotopes and elements: isotope = "%s%s" % (isotopes[i], elements[i]) set_spin_isotope(spin_id=spin_id, isotope=isotope, force=True) # Clean up the spin metadata. metadata_cleanup()
def ellipsoid_frame(): """Calculate the spherical angles of the bond vector in the ellipsoid frame.""" # Get the unit vectors Dx, Dy, and Dz of the diffusion tensor axes. Dx, Dy, Dz = diffusion_tensor.unit_axes() # Spin loop. for spin, mol_name, res_num, res_name in spin_loop(full_info=True): # Test if the vector exists. if not hasattr(spin, 'xh_vect'): # Get the spin id string. spin_id = generate_spin_id(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_num=spin.num, spin_name=spin.name) # Throw a warning. warn(RelaxWarning("No angles could be calculated for the spin " + repr(spin_id) + ".")) # Skip the spin. continue # dz and dx direction cosines. dz = dot(Dz, spin.xh_vect) dx = dot(Dx, spin.xh_vect) # Calculate the polar angle theta. spin.theta = acos(dz) # Calculate the azimuthal angle phi. spin.phi = acos(dx / sin(spin.theta))
def generate(mol_name=None, res_num=None, res_name=None, spin_num=None, spin_name=None, pipe=None, select=True, verbose=True): """Generate the sequence item-by-item by adding a single molecule/residue/spin container as necessary. @keyword mol_name: The molecule name. @type mol_name: str or None @keyword res_num: The residue number. @type res_num: int or None @keyword res_name: The residue name. @type res_name: str or None @keyword spin_num: The spin number. @type spin_num: int or None @keyword spin_name: The spin name. @type spin_name: str or None @keyword pipe: The data pipe in which to generate the sequence. This defaults to the current data pipe. @type pipe: str @keyword select: The spin selection flag. @type select: bool @keyword verbose: A flag which if True will cause info about each spin to be printed out as the sequence is generated. @type verbose: bool """ # The current data pipe. if pipe == None: pipe = pipes.cdp_name() # A new molecule. if not return_molecule(generate_spin_id(mol_name=mol_name), pipe=pipe): create_molecule(mol_name=mol_name, pipe=pipe) # A new residue. curr_res = return_residue(generate_spin_id(mol_name=mol_name, res_num=res_num, res_name=res_name), pipe=pipe) if not curr_res or ((res_num != None and curr_res.num != res_num) or (res_name != None and curr_res.name != res_name)): create_residue(mol_name=mol_name, res_num=res_num, res_name=res_name, pipe=pipe) # A new spin. curr_spin = return_spin(generate_spin_id(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_num=spin_num, spin_name=spin_name), pipe=pipe) if not curr_spin or ((spin_num != None and curr_spin.num != spin_num) or (spin_name != None and curr_spin.name != spin_name)): # Add the spin. curr_spin = create_spin(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_num=spin_num, spin_name=spin_name, pipe=pipe) # Set the selection flag. curr_spin.select = select
def generate(mol_name=None, res_num=None, res_name=None, spin_num=None, spin_name=None, pipe=None, select=True, verbose=True): """Generate the sequence item-by-item by adding a single molecule/residue/spin container as necessary. @keyword mol_name: The molecule name. @type mol_name: str or None @keyword res_num: The residue number. @type res_num: int or None @keyword res_name: The residue name. @type res_name: str or None @keyword spin_num: The spin number. @type spin_num: int or None @keyword spin_name: The spin name. @type spin_name: str or None @keyword pipe: The data pipe in which to generate the sequence. This defaults to the current data pipe. @type pipe: str @keyword select: The spin selection flag. @type select: bool @keyword verbose: A flag which if True will cause info about each spin to be printed out as the sequence is generated. @type verbose: bool """ # The current data pipe. if pipe == None: pipe = pipes.cdp_name() # A new molecule. if not return_molecule(generate_spin_id(mol_name=mol_name), pipe=pipe): create_molecule(mol_name=mol_name, pipe=pipe) # A new residue. curr_res = return_residue(generate_spin_id(mol_name=mol_name, res_num=res_num, res_name=res_name), pipe=pipe) if not curr_res or ((res_num != None and curr_res.num != res_num) or (res_name != None and curr_res.name != res_name)): create_residue(mol_name=mol_name, res_num=res_num, res_name=res_name, pipe=pipe) # A new spin. curr_spin = return_spin(spin_id=generate_spin_id(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_num=spin_num, spin_name=spin_name), pipe=pipe) if not curr_spin or ((spin_num != None and curr_spin.num != spin_num) or (spin_name != None and curr_spin.name != spin_name)): # Add the spin. curr_spin = create_spin(mol_name=mol_name, res_num=res_num, res_name=res_name, spin_num=spin_num, spin_name=spin_name, pipe=pipe)[0] # Set the selection flag. curr_spin.select = select
def attach_protons(): """Attach a single proton to all heteronuclei.""" # Loop over all spins. mol_names = [] res_nums = [] res_names = [] for spin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True): # The spin is already a proton. if hasattr(spin, 'element') and spin.element == 'H': continue # Get the interatomic data container. interatoms = return_interatom_list(spin_id) proton_found = False if len(interatoms): for i in range(len(interatoms)): # Get the attached spin. spin_attached = return_spin(interatoms[i].spin_id1) if id(spin_attached) == id(spin): spin_attached = return_spin(interatoms[i].spin_id2) # Is it a proton? if hasattr(spin_attached, 'element') and spin_attached.element == 'H' or spin.name == 'H': proton_found = True break # Attached proton found. if proton_found: continue # Store the sequence info. mol_names.append(mol_name) res_nums.append(res_num) res_names.append(res_name) # Create all protons (this must be done out of the spin loop, as it affects the looping!). ids = [] for i in range(len(mol_names)): # Create the spin container. spin = create_spin(spin_name='H', res_name=res_names[i], res_num=res_nums[i], mol_name=mol_names[i]) ids.append(generate_spin_id(mol_name=mol_names[i], res_num=res_nums[i], res_name=res_names[i], spin_name='H')) print("Creating the spins %s." % ids) # Set the element and spin type. set_spin_element(spin_id='@H', element='H') set_spin_isotope(spin_id='@H', isotope='1H')
def attach_protons(): """Attach a single proton to all heteronuclei.""" # Loop over all spins. mol_names = [] res_nums = [] res_names = [] for spin, mol_name, res_num, res_name, spin_id in spin_loop(full_info=True, return_id=True): # The spin is already a proton. if hasattr(spin, 'element') and spin.element == 'H': continue # Get the interatomic data container. interatoms = return_interatom_list(spin_hash=spin._hash) proton_found = False if len(interatoms): for i in range(len(interatoms)): # Get the attached spin. spin_attached = return_spin(spin_hash=interatoms[i]._spin_hash1) if id(spin_attached) == id(spin): spin_attached = return_spin(spin_hash=interatoms[i]._spin_hash2) # Is it a proton? if hasattr(spin_attached, 'element') and spin_attached.element == 'H' or spin.name == 'H': proton_found = True break # Attached proton found. if proton_found: continue # Store the sequence info. mol_names.append(mol_name) res_nums.append(res_num) res_names.append(res_name) # Create all protons (this must be done out of the spin loop, as it affects the looping!). ids = [] for i in range(len(mol_names)): # Create the spin container. spin = create_spin(spin_name='H', res_name=res_names[i], res_num=res_nums[i], mol_name=mol_names[i])[0] ids.append(generate_spin_id(mol_name=mol_names[i], res_num=res_nums[i], res_name=res_names[i], spin_name='H')) print("Creating the spins %s." % ids) # Set the element and spin type. set_spin_element(spin_id='@H', element='H') set_spin_isotope(spin_id='@H', isotope='1H')
def generate_sequence(N=0, spin_ids=None, spin_nums=None, spin_names=None, res_nums=None, res_names=None, mol_names=None, isotopes=None, elements=None): """Generate the sequence data from the BRMB information. @keyword N: The number of spins. @type N: int @keyword spin_ids: The list of spin IDs. @type spin_ids: list of str @keyword spin_nums: The list of spin numbers. @type spin_nums: list of int or None @keyword spin_names: The list of spin names. @type spin_names: list of str or None @keyword res_nums: The list of residue numbers. @type res_nums: list of int or None @keyword res_names: The list of residue names. @type res_names: list of str or None @keyword mol_names: The list of molecule names. @type mol_names: list of str or None @keyword isotopes: The optional list of isotope types. @type isotopes: list of str or None @keyword elements: The optional list of element types. @type elements: list of str or None """ # The blank data. if not spin_nums: spin_nums = [None] * N if not spin_names: spin_names = [None] * N if not res_nums: res_nums = [None] * N if not res_names: res_names = [None] * N if not mol_names: mol_names = [None] * N # Generate the spin IDs. spin_ids = [] for i in range(N): spin_ids.append( generate_spin_id(mol_name=mol_names[i], res_num=res_nums[i], spin_name=spin_names[i])) # Loop over the spin data. for i in range(N): # The spin already exists. spin = return_spin(spin_id=spin_ids[i]) if spin: continue # Create the spin. spin = create_spin(spin_num=spin_nums[i], spin_name=spin_names[i], res_num=res_nums[i], res_name=res_names[i], mol_name=mol_names[i])[0] # Set the spin isotope and element. spin_id = spin._spin_ids[0] if elements: set_spin_element(spin_id=spin_id, element=elements[i], force=True) if isotopes and elements: isotope = "%s%s" % (isotopes[i], elements[i]) set_spin_isotope(spin_id=spin_id, isotope=isotope, force=True) # Clean up the spin metadata. metadata_cleanup()
# Unit vector. r_hat = r / norm(r) # The PCS (in ppm). pcs = 1.0 / (4.0 * pi * norm(r)**3) * dot(transpose(r_hat), dot(chi_tensor, r_hat)) pcs = pcs * 1e6 # Write the PCS. pcs_file.write("%20s%10s%10s%10s%10s%30.11g%30.11g\n" % (mol, res_num, res_name, spin.num, spin.name, pcs, 1e-10)) # RDC time, so skip protons now. if spin.name == "H": continue # Get the interatomic data container. spin_id1 = generate_spin_id(res_num=res_num, res_name=res_name, spin_num=spin.num, spin_name=spin.name) spin_id2 = generate_spin_id(res_num=res_num, res_name=res_name, spin_name='H') interatom = return_interatom(spin_id1, spin_id2) # Skip interatoms without vectors. if not hasattr(interatom, 'vector'): continue # Calculate and write the RDC. rdc = dip_const * dot(transpose(interatom.vector), dot(tensor, interatom.vector)) rdc_file.write("%-10s %-10s %20.11f %20.11g\n" % (repr(spin_id1), repr(spin_id2), rdc, 1e-10)) # Print outs. print("\nAlignment tensor (A):\n" + repr(tensor)) print("Eigenvalues: " + repr(eigvals(tensor))) print("Dipolar constant: " + repr(dip_const))
# The PCS (in ppm). pcs = 1.0 / (4.0 * pi * norm(r)**3) * dot(transpose(r_hat), dot(chi_tensor, r_hat)) pcs = pcs * 1e6 # Write the PCS. pcs_file.write("%20s%10s%10s%10s%10s%30.11g\n" % (mol, res_num, res_name, spin.num, spin.name, pcs)) # RDC time, so skip protons now. if spin.name == "H": continue # Get the interatomic data container. spin_id1 = generate_spin_id(res_num=res_num, res_name=res_name, spin_num=spin.num, spin_name=spin.name) spin_id2 = generate_spin_id(res_num=res_num, res_name=res_name, spin_name='H') spin2 = return_spin(spin_id=spin_id2) interatom = return_interatom(spin_hash1=spin._hash, spin_hash2=spin2._hash) # Skip interatoms without vectors. if not hasattr(interatom, 'vector'): continue # Calculate and write the RDC. rdc = dip_const * dot(transpose(interatom.vector), dot(tensor, interatom.vector)) rdc_file.write("%-10s %-10s %20.11f\n" %