Author: bugman Date: Thu May 15 13:07:49 2014 New Revision: 23188 URL: http://svn.gna.org/viewcvs/relax?rev=23188&view=rev Log: Fix for bug #22041, the PDB atom serial number error from the structure.write_pdb user function. This was reported at https://gna.org/bugs/?22041. The problem is that the structure.write_pdb user function preserves the atom numbering from the original structure and uses that for the atom serial number. However the atom serial number must be replaced with sequential values to produce a valid PDB file. This is fatal for any CONECT records. Modified: trunk/lib/structure/internal/object.py Modified: trunk/lib/structure/internal/object.py URL: http://svn.gna.org/viewcvs/relax/trunk/lib/structure/internal/object.py?rev=23188&r1=23187&r2=23188&view=diff ============================================================================== --- trunk/lib/structure/internal/object.py (original) +++ trunk/lib/structure/internal/object.py Thu May 15 13:07:49 2014 @@ -2657,6 +2657,7 @@ # Loop over the molecules. index = 0 + atom_serial = 0 for mol in model.mol: # Print out. print("ATOM, HETATM, TER") @@ -2668,10 +2669,8 @@ if mol.pdb_record[i] in [None, 'ATOM']: atom_record = True - # The atom number, if missing. - atom_num = mol.atom_num[i] - if atom_num == None: - atom_num = i + 1 + # The atom number. + atom_serial += 1 # 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." @@ -2681,12 +2680,12 @@ atom_name = "%s" % mol.atom_name[i] # Write out. - pdb_write.atom(file, serial=atom_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=atom_serial, 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]) num_atom += 1 ser_num += 1 # Info for the TER record. - ter_num = atom_num + 1 + ter_num = atom_serial + 1 ter_name = mol.res_name[i] ter_chain_id = CHAIN_ID_LIST[index] ter_res_num = mol.res_num[i] @@ -2702,16 +2701,14 @@ for i in range(len(mol.atom_name)): # Write the HETATM record. if mol.pdb_record[i] == 'HETATM': - # The atom number, if missing. - atom_num = mol.atom_num[i] - if atom_num == None: - atom_num = i + 1 + # The atom number. + atom_serial += 1 # Increment the atom number if a TER record was created. - if atom_record and atom_num == ter_num: + if atom_record and atom_serial == ter_num: count_shift = True if atom_record and count_shift: - atom_num += 1 + atom_serial += 1 # Write out. pdb_write.hetatm(file, serial=ser_num, name=self._translate(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.0, element=mol.element[i])