Author: bugman Date: Tue Apr 8 14:39:03 2008 New Revision: 5430 URL: http://svn.gna.org/viewcvs/relax?rev=5430&view=rev Log: Merged generic_fns.sequence.load_PDB_sequence() into generic_fns.structure.main.load_spins(). Modified: 1.3/generic_fns/sequence.py 1.3/generic_fns/structure/main.py Modified: 1.3/generic_fns/sequence.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/sequence.py?rev=5430&r1=5429&r2=5430&view=diff ============================================================================== --- 1.3/generic_fns/sequence.py (original) +++ 1.3/generic_fns/sequence.py Tue Apr 8 14:39:03 2008 @@ -55,120 +55,6 @@ # Write the data. write_body(file=sys.stdout, mol_name_col=mol_name_col, res_num_col=res_num_col, res_name_col=res_name_col, spin_num_col=spin_num_col, spin_name_col=spin_name_col, sep=sep) - - -def load_PDB_sequence(spin_id=None): - """Function for loading the sequence out of a PDB file. - - @param spin_id: The molecule, residue, and spin identifier string. - @type spin_id: str - """ - - # Print out. - print "\nLoading the sequence from the PDB file.\n" - - # Alias the current data pipe. - cdp = relax_data_store[relax_data_store.current_pipe] - - # Reassign the sequence of the first structure. - if cdp.structure.structures[0].peptide_chains: - chains = cdp.structure.structures[0].peptide_chains - molecule = 'protein' - elif cdp.structure.structures[0].nucleotide_chains: - chains = cdp.structure.structures[0].nucleotide_chains - molecule = 'nucleic acid' - else: - raise RelaxNoPdbChainError - - # Split up the selection string. - mol_token, res_token, spin_token = tokenise(spin_id) - - # Parse the tokens. - molecules = parse_token(mol_token) - residues = parse_token(res_token) - spins = parse_token(spin_token) - - # Init some indecies. - mol_index = 0 - res_index = 0 - spin_index = 0 - - # Loop over the molecules. - for chain in chains: - # The name of the molecule. - if chain.chain_id: - mol_name = chain.chain_id - elif chain.segment_id: - mol_name = chain.segment_id - else: - mol_name = None - - # Skip non-matching molecules. - if mol_token and mol_name not in molecules: - continue - - # Add the molecule if there is a molecule name (otherwise everything goes into the default first MolecularContainer). - if mol_name: - # Replace the first empty molecule. - if mol_index == 0 and cdp.mol[0].name == None: - cdp.mol[0].name = mol_name - - # Create a new molecule. - else: - # Add the molecule. - cdp.mol.add_item(mol_name=mol_name) - - # Loop over the residues. - for res in chain.residues: - # The residue name and number. - if molecule == 'nucleic acid': - res_name = res.name[-1] - else: - res_name = res.name - res_num = res.number - - # Skip non-matching residues. - if res_token and not (res_name in residues or res_num in residues): - continue - - # Replace the first empty residue. - if res_index == 0 and cdp.mol[mol_index].res[0].name == None: - cdp.mol[mol_index].res[0].name = res_name - cdp.mol[mol_index].res[0].num = res_num - - # Create a new residue. - else: - # Add the residue. - cdp.mol[mol_index].res.add_item(res_name=res_name, res_num=res_num) - - # Loop over the spins. - for atom in res.atom_list: - # The spin name and number. - spin_name = atom.name - spin_num = atom.properties['serial_number'] - - # Skip non-matching spins. - if spin_token and not (spin_name in spins or spin_num in spins): - continue - - # Replace the first empty residue. - if spin_index == 0 and cdp.mol[mol_index].res[res_index].spin[0].name == None: - cdp.mol[mol_index].res[res_index].spin[0].name = spin_name - cdp.mol[mol_index].res[res_index].spin[0].num = spin_num - - # Create a new residue. - else: - # Add the residue. - cdp.mol[mol_index].res[res_index].spin.add_item(spin_name=spin_name, spin_num=spin_num) - - # Increment the residue index. - spin_index = spin_index + 1 - - # Increment the residue index. - res_index = res_index + 1 - - # Increment the molecule index. - mol_index = mol_index + 1 def read(file=None, dir=None, mol_name_col=None, res_num_col=0, res_name_col=1, spin_num_col=None, spin_name_col=None, sep=None): Modified: 1.3/generic_fns/structure/main.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/structure/main.py?rev=5430&r1=5429&r2=5430&view=diff ============================================================================== --- 1.3/generic_fns/structure/main.py (original) +++ 1.3/generic_fns/structure/main.py Tue Apr 8 14:39:03 2008 @@ -39,16 +39,119 @@ def load_spins(spin_id=None): """Load the spins from the structural object into the relax data store. - @keyword spin_id: The spin identification string. - @type spin_id: str + @keyword spin_id: The molecule, residue, and spin identifier string. + @type spin_id: str """ # Test if the current data pipe exists. if not relax_data_store.current_pipe: raise RelaxNoPipeError + # Print out. + print "Generating the spins from the loaded structure.\n" + # Alias the current data pipe. cdp = relax_data_store[relax_data_store.current_pipe] + + # Reassign the sequence of the first structure. + if cdp.structure.structures[0].peptide_chains: + chains = cdp.structure.structures[0].peptide_chains + molecule = 'protein' + elif cdp.structure.structures[0].nucleotide_chains: + chains = cdp.structure.structures[0].nucleotide_chains + molecule = 'nucleic acid' + else: + raise RelaxNoPdbChainError + + # Split up the selection string. + mol_token, res_token, spin_token = tokenise(spin_id) + + # Parse the tokens. + molecules = parse_token(mol_token) + residues = parse_token(res_token) + spins = parse_token(spin_token) + + # Init some indecies. + mol_index = 0 + res_index = 0 + spin_index = 0 + + # Loop over the molecules. + for chain in chains: + # The name of the molecule. + if chain.chain_id: + mol_name = chain.chain_id + elif chain.segment_id: + mol_name = chain.segment_id + else: + mol_name = None + + # Skip non-matching molecules. + if mol_token and mol_name not in molecules: + continue + + # Add the molecule if there is a molecule name (otherwise everything goes into the default first MolecularContainer). + if mol_name: + # Replace the first empty molecule. + if mol_index == 0 and cdp.mol[0].name == None: + cdp.mol[0].name = mol_name + + # Create a new molecule. + else: + # Add the molecule. + cdp.mol.add_item(mol_name=mol_name) + + # Loop over the residues. + for res in chain.residues: + # The residue name and number. + if molecule == 'nucleic acid': + res_name = res.name[-1] + else: + res_name = res.name + res_num = res.number + + # Skip non-matching residues. + if res_token and not (res_name in residues or res_num in residues): + continue + + # Replace the first empty residue. + if res_index == 0 and cdp.mol[mol_index].res[0].name == None: + cdp.mol[mol_index].res[0].name = res_name + cdp.mol[mol_index].res[0].num = res_num + + # Create a new residue. + else: + # Add the residue. + cdp.mol[mol_index].res.add_item(res_name=res_name, res_num=res_num) + + # Loop over the spins. + for atom in res.atom_list: + # The spin name and number. + spin_name = atom.name + spin_num = atom.properties['serial_number'] + + # Skip non-matching spins. + if spin_token and not (spin_name in spins or spin_num in spins): + continue + + # Replace the first empty residue. + if spin_index == 0 and cdp.mol[mol_index].res[res_index].spin[0].name == None: + cdp.mol[mol_index].res[res_index].spin[0].name = spin_name + cdp.mol[mol_index].res[res_index].spin[0].num = spin_num + + # Create a new residue. + else: + # Add the residue. + cdp.mol[mol_index].res[res_index].spin.add_item(spin_name=spin_name, spin_num=spin_num) + + # Increment the residue index. + spin_index = spin_index + 1 + + # Increment the residue index. + res_index = res_index + 1 + + # Increment the molecule index. + mol_index = mol_index + 1 def read_pdb(file=None, dir=None, model=None, parser='scientific', fail=True, verbosity=1):