Author: bugman Date: Wed Oct 1 13:39:36 2008 New Revision: 7471 URL: http://svn.gna.org/viewcvs/relax?rev=7471&view=rev Log: Converted the create_vector_dist() function to the new design. Again the problem was identified by looking at incorrect usage of the relax data store. Modified: branches/pipe_refs/generic_fns/structure/geometric.py Modified: branches/pipe_refs/generic_fns/structure/geometric.py URL: http://svn.gna.org/viewcvs/relax/branches/pipe_refs/generic_fns/structure/geometric.py?rev=7471&r1=7470&r2=7471&view=diff ============================================================================== --- branches/pipe_refs/generic_fns/structure/geometric.py (original) +++ branches/pipe_refs/generic_fns/structure/geometric.py Wed Oct 1 13:39:36 2008 @@ -305,11 +305,9 @@ tensor_pdb_file.close() -def create_vector_dist(run=None, length=None, symmetry=1, file=None, dir=None, force=False): +def create_vector_dist(length=None, symmetry=1, file=None, dir=None, force=False): """Create a PDB representation of the XH vector distribution. - @param run: The run. - @type run: str @param length: The length to set the vectors to in the PDB file. @type length: float @param symmetry: The symmetry flag which if set will create a second PDB chain 'B' which @@ -320,31 +318,31 @@ @param dir: The name of the directory to place the PDB file into. @type dir: str @param force: Flag which if set will overwrite any pre-existing file. - @type force: int + @type force: bool """ - - # Arguments. - run = run # Test if the current pipe exists. pipes.test() - # Test if the PDB file of the macromolecule has been loaded. - if not ds.pdb.has_key(run): - raise RelaxNoPdbError, run + # Get the data pipe. + cdp = pipes.get_pipe() + + # Test if a structure has been loaded. + if not hasattr(cdp, 'structure') or not cdp.structure.num > 0: + raise RelaxNoPdbError # Test if sequence data is loaded. - if not len(ds.res[run]): - raise RelaxNoSequenceError, run + if not exists_mol_res_spin_data(): + raise RelaxNoSequenceError # Test if unit vectors exist. vectors = 0 - for i in xrange(len(ds.res[run])): - if hasattr(ds.res[run][i], 'xh_vect'): + for spin in spin_loop(): + if hasattr(spin, 'xh_vect'): vectors = 1 break if not vectors: - raise RelaxNoVectorsError, run + raise RelaxNoVectorsError # Initialise. @@ -353,8 +351,9 @@ # Create the structural object. structure = Internal() - # Initialise the residue number. + # Initialise the residue and atom numbers. res_num = 1 + atom_num = 1 # Centre of mass. @@ -371,81 +370,53 @@ ################# # Loop over the spin systems. - for i in xrange(len(ds.res[run])): - # Alias the spin system data. - data = ds.res[run][i] - + for spin in spin_loop(): # Skip deselected spin systems. - if not data.select: + if not spin.select: continue # Skip spin systems missing the xh_vect structure. - if not hasattr(data, 'xh_vect'): + if not hasattr(spin, 'xh_vect'): continue # Scale the vector. - vector = data.xh_vect * length * 1e10 - - # The atom ids. - end = '_' + `data.num` + '_' + data.name - X_id = data.heteronuc + end - H_id = data.proton + end + vector = spin.xh_vect * length * 1e10 # Add the central X atom. - structure.atom_add(pdb_record='ATOM', atom_num=X_id, atom_name=data.heteronuc, res_name=data.name, chain_id='A', res_num=data.num, pos=R, segment_id=None, element=data.heteronuc, struct_index=None) + structure.atom_add(pdb_record='ATOM', atom_num=atom_num, atom_name=spin.heteronuc, res_name=spin.name, chain_id='A', res_num=spin.num, pos=R, segment_id=None, element=spin.heteronuc, struct_index=None) # Add the H atom. - structure.atom_add(pdb_record='ATOM', atom_num=H_id, atom_name=data.proton, res_name=data.name, chain_id='A', res_num=data.num, pos=R+vector, segment_id=None, element=data.proton, struct_index=None) + structure.atom_add(pdb_record='ATOM', atom_num=atom_num+1, atom_name=spin.proton, res_name=spin.name, chain_id='A', res_num=spin.num, pos=R+vector, segment_id=None, element=spin.proton, struct_index=None) # Connect the two atoms. - structure.atom_connect(index1=X_id, index2=H_id) - - # Store the terminate residue number for the TER record. - last_res = data.num - last_name = data.name - - # The TER record. - structure.atom_add(pdb_record='TER', atom_num=None, atom_name='TER' + '_A', res_name=last_name, chain_id='A', res_num=last.res, pos=R, segment_id=None, element=None, struct_index=None) + structure.atom_connect(index1=atom_num-1, index2=atom_num) + + # Increment the atom number. + atom_num = atom_num + 2 # Symmetry chain. if symmetry: # Loop over the spin systems. - for i in xrange(len(ds.res[run])): - # Alias the spin system data. - data = ds.res[run][i] - + for spin in spin_loop(): # Skip deselected spin systems. - if not data.select: + if not spin.select: continue # Skip spin systems missing the xh_vect structure. - if not hasattr(data, 'xh_vect'): + if not hasattr(spin, 'xh_vect'): continue # Scale the vector. - vector = data.xh_vect * length * 1e10 - - # The atom ids. - end = '_' + `data.num` + '_' + data.name - X_id = data.heteronuc + end - H_id = data.proton + end + vector = spin.xh_vect * length * 1e10 # Add the central X atom. - structure.atom_add(pdb_record='ATOM', atom_num=X_id + 'B', atom_name=data.heteronuc, res_name=data.name, chain_id='B', res_num=data.num, pos=R, segment_id=None, element=data.heteronuc, struct_index=None) + structure.atom_add(pdb_record='ATOM', atom_num=atom_num, atom_name=spin.heteronuc, res_name=spin.name, chain_id='B', res_num=spin.num, pos=R, segment_id=None, element=spin.heteronuc, struct_index=None) # Add the H atom. - structure.atom_add(pdb_record='ATOM', atom_num=H_id + 'B', atom_name=data.proton, res_name=data.name, chain_id='B', res_num=data.num, pos=R+vector, segment_id=None, element=data.proton, struct_index=None) + structure.atom_add(pdb_record='ATOM', atom_num=atom_num+1, atom_name=spin.proton, res_name=spin.name, chain_id='B', res_num=spin.num, pos=R+vector, segment_id=None, element=spin.proton, struct_index=None) # Connect the two atoms. - structure.atom_connect(index1=X_id + '_B', index2=H_id + '_B') - - # Store the terminate residue number for the TER record. - last_res = data.num - last_name = data.name - - # The TER record. - structure.atom_add(pdb_record='TER', atom_num=None, atom_name='TER' + '_B', res_name=last_name, chain_id='B', res_num=last.res, pos=R, segment_id=None, element=None, struct_index=None) - + structure.atom_connect(index1=atom_num-1, index2=atom_num) # Create the PDB file.