Author: bugman Date: Fri Feb 20 15:49:23 2015 New Revision: 27700 URL: http://svn.gna.org/viewcvs/relax?rev=27700&view=rev Log: Bug fix for the SHEET PDB records created by the structure.write_pdb user function. The current and previous atom parts of the record were not being correctly formatted. This was simply using the %4s formatting string. However the PDB atom format is rather more complicated. To handle this, the new _handle_atom_name() helper function has been added to the lib.structure.pdb_write module. This is now used in the atom() and sheet() functions for consistently formatting the atom name field. Modified: trunk/lib/structure/internal/object.py trunk/lib/structure/pdb_write.py Modified: trunk/lib/structure/internal/object.py URL: http://svn.gna.org/viewcvs/relax/trunk/lib/structure/internal/object.py?rev=27700&r1=27699&r2=27700&view=diff ============================================================================== --- trunk/lib/structure/internal/object.py (original) +++ trunk/lib/structure/internal/object.py Fri Feb 20 15:49:23 2015 @@ -3070,15 +3070,8 @@ if mol.pdb_record[i] in [None, 'ATOM']: atom_record = True - # Handle the funky atom name alignment. From the PDB format documents: - # "Alignment of one-letter atom name such as C starts at column 14, while two-letter atom name such as FE starts at column 13." - if len(mol.atom_name[i]) == 1: - atom_name = " %s" % mol.atom_name[i] - else: - atom_name = "%s" % mol.atom_name[i] - # Write out. - pdb_write.atom(file, serial=ser_num, name=atom_name, res_name=mol.res_name[i], chain_id=CHAIN_ID_LIST[index], res_seq=mol.res_num[i], x=mol.x[i], y=mol.y[i], z=mol.z[i], occupancy=1.0, temp_factor=0, element=mol.element[i]) + pdb_write.atom(file, serial=ser_num, name=mol.atom_name[i], res_name=mol.res_name[i], chain_id=CHAIN_ID_LIST[index], res_seq=mol.res_num[i], x=mol.x[i], y=mol.y[i], z=mol.z[i], occupancy=1.0, temp_factor=0, element=mol.element[i]) num_atom += 1 ser_num += 1 Modified: trunk/lib/structure/pdb_write.py URL: http://svn.gna.org/viewcvs/relax/trunk/lib/structure/pdb_write.py?rev=27700&r1=27699&r2=27700&view=diff ============================================================================== --- trunk/lib/structure/pdb_write.py (original) +++ trunk/lib/structure/pdb_write.py Fri Feb 20 15:49:23 2015 @@ -30,6 +30,40 @@ # relax module imports. from lib.errors import RelaxError + + +def _handle_atom_name(name): + """Handle the funky PDB atom name alignment. + + From the PDB format documents: + + "Alignment of one-letter atom name such as C starts at column 14, while two-letter atom name such as FE starts at column 13." + + + @param name: The atom name. + @type name: str or None + @return: The whitespace padded and PDB formatted atom name. This will be exactly 4 characters. + @rtype: str + """ + + # Handle none. + if name == None: + name = " " + + # Single letter name. + if len(name) == 1: + name = " %s " % name + + # Two letter name. + elif len(name) == 2: + name = "%s " % name + + # Three letter name. + elif len(name) == 3: + name = "%s " % name + + # Return the name. + return name def _handle_none(value): @@ -283,7 +317,7 @@ text = "%-6s%5s %-4s%1s%3s %1s%4s%1s %8.3f%8.3f%8.3f%6.2f%6.2f %2s%2s" % ( 'ATOM', _handle_none(serial), - _handle_none(name), + _handle_atom_name(name), _handle_none(alt_loc), _handle_none(res_name), _handle_none(chain_id), @@ -1725,12 +1759,12 @@ _handle_none(end_seq_num), _handle_none(end_icode), _handle_none(sense), - _handle_none(cur_atom), + _handle_atom_name(cur_atom), _handle_none(cur_res_name), _handle_none(cur_chain_id), _handle_none(cur_res_seq), _handle_none(cur_icode), - _handle_none(prev_atom), + _handle_atom_name(prev_atom), _handle_none(prev_res_name), _handle_none(prev_chain_id), _handle_none(prev_res_seq),