Author: bugman Date: Tue Apr 8 15:10:12 2008 New Revision: 5431 URL: http://svn.gna.org/viewcvs/relax?rev=5431&view=rev Log: Completion of generic_fns.structure.main.load_spins() and allowed atom selections in atom_loop(). The generic_fns.structure.main.load_spins() function now uses the structural data object API method atom_loop() to generate the molecule, residue, and spin sequence in the relax data store. The sequence generation code is mainly from the old load_PDB_sequence() function. The Scientific Python data object atom_loop() generator method has been updated to allow for only selected atoms to be yielded. Modified: 1.3/generic_fns/sequence.py 1.3/generic_fns/structure/main.py 1.3/generic_fns/structure/scientific.py Modified: 1.3/generic_fns/sequence.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/sequence.py?rev=5431&r1=5430&r2=5431&view=diff ============================================================================== --- 1.3/generic_fns/sequence.py (original) +++ 1.3/generic_fns/sequence.py Tue Apr 8 15:10:12 2008 @@ -22,7 +22,7 @@ # relax module imports. from data import Data as relax_data_store -from generic_fns.selection import count_spins, exists_mol_res_spin_data, parse_token, spin_loop, tokenise +from generic_fns.selection import count_spins, exists_mol_res_spin_data, spin_loop from relax_errors import RelaxError, RelaxFileEmptyError, RelaxNoPdbChainError, RelaxNoPipeError, RelaxNoSequenceError, RelaxSequenceError from relax_io import extract_data, open_write_file, strip import sys Modified: 1.3/generic_fns/structure/main.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/structure/main.py?rev=5431&r1=5430&r2=5431&view=diff ============================================================================== --- 1.3/generic_fns/structure/main.py (original) +++ 1.3/generic_fns/structure/main.py Tue Apr 8 15:10:12 2008 @@ -53,105 +53,40 @@ # 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 + # Loop over all atoms of the spin_id selection. + for mol_name, res_num, res_name, atom_num, atom_name, pos in cdp.structure.atom_loop(spin_id=spin_id, pos=True): + # Get the corresponding molecule container. + mol_cont = return_molecule('#' + mol_name) + + # Add the molecule if it doesn't exist. + if mol_name and mol_cont == None: + # Add the molecule. + cdp.mol.add_item(mol_name=mol_name) + + # Get the container. + mol_cont = cdp.mol[-1] + + # Get the corresponding residue container (residue name is ignored because only the number is unique). + res_cont = return_residue(':' + `res_num`) + + # Add the residue if it doesn't exist. + if res_num and res_name and res_cont == None: + # Add the residue. + mol_cont.res.add_item(res_name=res_name, res_num=res_num) + + # Get the container. + res_cont = mol_cont.res[-1] + + # Get the corresponding spin container (spin name is ignored because only the number is unique). + spin_cont = return_spin(':' + `spin_num`) + + # Add the spin if it doesn't exist. + if spin_name and spin_cont == None: + # Add the spin. + res_cont.spin.add_item(spin_name=spin_name, spin_num=spin_num) + + # Get the container. + spin_cont = res_cont.spin[-1] def read_pdb(file=None, dir=None, model=None, parser='scientific', fail=True, verbosity=1): Modified: 1.3/generic_fns/structure/scientific.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/structure/scientific.py?rev=5431&r1=5430&r2=5431&view=diff ============================================================================== --- 1.3/generic_fns/structure/scientific.py (original) +++ 1.3/generic_fns/structure/scientific.py Tue Apr 8 15:10:12 2008 @@ -39,6 +39,7 @@ # relax module imports. from api_base import Str_object from data import Data as relax_data_store +from generic_fns.selection import parse_token, tokenise from relax_errors import RelaxNoPdbChainError, RelaxNoResError, RelaxPdbLoadError from relax_warnings import RelaxNoAtomWarning, RelaxZeroVectorWarning @@ -63,15 +64,29 @@ array of len 3) """ + # Split up the selection string. + mol_token, res_token, atom_token = tokenise(atom_id) + + # Parse the tokens. + molecules = parse_token(mol_token) + residues = parse_token(res_token) + atoms = parse_token(atom_token) + # Loop over the loaded structures. for struct in self.structural_data: # Protein. if struct.peptide_chains: chains = struct.peptide_chains + molecule = 'protein' # RNA/DNA. elif struct.nucleotide_chains: chains = struct.nucleotide_chains + molecule = 'nucleic acid' + + # We have a problem! + else: + raise RelaxNoPdbChainError # Loop over the chains (each of which will be treated as a new molecule). for chain in chains: @@ -83,11 +98,22 @@ else: mol_name = None + # Skip non-matching molecules. + if mol_token and mol_name not in molecules: + continue + # Loop over the residues of the protein in the PDB file. for res in chain.residues: # Residue number and name. + if molecule == 'nucleic acid': + res_name = res.name[-1] + else: + res_name = res.name res_num = res.number - res_name = res.name + + # Skip non-matching residues. + if res_token and not (res_name in residues or res_num in residues): + continue # Loop over the atoms of the residue. for atom in res: @@ -95,6 +121,10 @@ atom_num = atom.properties['serial_number'] atom_name = atom.properties['element'] pos = atom.position.array + + # Skip non-matching atoms. + if atom_token and not (atom_name in atoms or atom_num in atoms): + continue # Yield the information. if pos: