Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -552,4 +552,79 @@ public void testCorrectAtomNamePadding() throws IOException {
assertTrue("the created PDB file does not match the input file", pdb.equals(atomLines));

}

/**
* Test handling of missing Element column. Issue 537 in github.
* @author Aleix Lafita
* @throws IOException
*/
@Test
public void testMissingElements() throws IOException {

// A two residue structure without Element column
String missingElement =
"ATOM 1 N ASP L 1A 11.095 19.341 20.188 1.00 30.14"+newline+
"ATOM 2 CA ASP L 1A 10.070 18.634 19.379 1.00 28.34"+newline+
"ATOM 3 C ASP L 1A 9.846 17.102 19.503 1.00 26.08"+newline+
"ATOM 4 O ASP L 1A 8.744 16.584 19.162 1.00 23.47"+newline+
"ATOM 5 CB ASP L 1A 10.255 18.858 17.853 1.00 37.55"+newline+
"ATOM 6 CG ASP L 1A 8.836 19.264 17.401 1.00 42.76"+newline+
"ATOM 7 OD1 ASP L 1A 8.058 19.292 18.400 1.00 44.03"+newline+
"ATOM 8 OD2 ASP L 1A 8.616 19.668 16.244 1.00 46.88"+newline+
"ATOM 9 N CYS L 1 10.835 16.440 20.113 1.00 23.72"+newline+
"ATOM 10 CA CYS L 1 10.769 14.970 20.210 1.00 20.89"+newline+
"ATOM 11 C CYS L 1 9.580 14.524 21.006 1.00 18.64"+newline+
"ATOM 12 O CYS L 1 9.110 15.220 21.912 1.00 19.03"+newline+
"ATOM 13 CB CYS L 1 12.117 14.468 20.771 1.00 21.77"+newline+
"ATOM 14 SG CYS L 1 12.247 14.885 22.538 1.00 20.55"+newline+
"TER "+newline;

// A two residue structure with empty Element column
String emptyElement =
"ATOM 1 N ASP L 1A 11.095 19.341 20.188 1.00 30.14 "+newline+
"ATOM 2 CA ASP L 1A 10.070 18.634 19.379 1.00 28.34 "+newline+
"ATOM 3 C ASP L 1A 9.846 17.102 19.503 1.00 26.08 "+newline+
"ATOM 4 O ASP L 1A 8.744 16.584 19.162 1.00 23.47 "+newline+
"ATOM 5 CB ASP L 1A 10.255 18.858 17.853 1.00 37.55 "+newline+
"ATOM 6 CG ASP L 1A 8.836 19.264 17.401 1.00 42.76 "+newline+
"ATOM 7 OD1 ASP L 1A 8.058 19.292 18.400 1.00 44.03 "+newline+
"ATOM 8 OD2 ASP L 1A 8.616 19.668 16.244 1.00 46.88 "+newline+
"ATOM 9 N CYS L 1 10.835 16.440 20.113 1.00 23.72 "+newline+
"ATOM 10 CA CYS L 1 10.769 14.970 20.210 1.00 20.89 "+newline+
"ATOM 11 C CYS L 1 9.580 14.524 21.006 1.00 18.64 "+newline+
"ATOM 12 O CYS L 1 9.110 15.220 21.912 1.00 19.03 "+newline+
"ATOM 13 CB CYS L 1 12.117 14.468 20.771 1.00 21.77 "+newline+
"ATOM 14 SG CYS L 1 12.247 14.885 22.538 1.00 20.55 "+newline+
"TER "+newline;

String original =
"ATOM 1 N ASP L 1A 11.095 19.341 20.188 1.00 30.14 N"+newline+
"ATOM 2 CA ASP L 1A 10.070 18.634 19.379 1.00 28.34 C"+newline+
"ATOM 3 C ASP L 1A 9.846 17.102 19.503 1.00 26.08 C"+newline+
"ATOM 4 O ASP L 1A 8.744 16.584 19.162 1.00 23.47 O"+newline+
"ATOM 5 CB ASP L 1A 10.255 18.858 17.853 1.00 37.55 C"+newline+
"ATOM 6 CG ASP L 1A 8.836 19.264 17.401 1.00 42.76 C"+newline+
"ATOM 7 OD1 ASP L 1A 8.058 19.292 18.400 1.00 44.03 O"+newline+
"ATOM 8 OD2 ASP L 1A 8.616 19.668 16.244 1.00 46.88 O"+newline+
"ATOM 9 N CYS L 1 10.835 16.440 20.113 1.00 23.72 N"+newline+
"ATOM 10 CA CYS L 1 10.769 14.970 20.210 1.00 20.89 C"+newline+
"ATOM 11 C CYS L 1 9.580 14.524 21.006 1.00 18.64 C"+newline+
"ATOM 12 O CYS L 1 9.110 15.220 21.912 1.00 19.03 O"+newline+
"ATOM 13 CB CYS L 1 12.117 14.468 20.771 1.00 21.77 C"+newline+
"ATOM 14 SG CYS L 1 12.247 14.885 22.538 1.00 20.55 S"+newline+
"TER "+newline;


BufferedReader br = new BufferedReader(new StringReader(missingElement));
Structure s = parser.parsePDBFile(br);
String pdb = s.toPDB();
assertTrue("the Element column has not been filled correctly", pdb.equals(original));


br = new BufferedReader(new StringReader(emptyElement));
s = parser.parsePDBFile(br);
pdb = s.toPDB();
assertTrue("the Element column has not been filled correctly", pdb.equals(original));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import org.biojava.nbio.structure.StructureImpl;
import org.biojava.nbio.structure.StructureTools;
import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory;
import org.biojava.nbio.structure.io.mmcif.model.ChemCompAtom;
import org.biojava.nbio.structure.secstruc.SecStrucInfo;
import org.biojava.nbio.structure.secstruc.SecStrucType;
import org.biojava.nbio.structure.xtal.CrystalCell;
Expand Down Expand Up @@ -1825,30 +1826,50 @@ private void pdb_ATOM_Handler(String line) {

// Parse element from the element field. If this field is
// missing (i.e. misformatted PDB file), then parse the
// name from the atom name.
// element from the chemical component.
Element element = Element.R;
boolean guessElement = true;
if ( line.length() > 77 ) {
// parse element from element field
try {
element = Element.valueOfIgnoreCase(line.substring (76, 78).trim());
} catch (IllegalArgumentException e){}
String elementSymbol = line.substring(76, 78).trim();
if (elementSymbol.isEmpty()) {
logger.warn("Element column was empty for atom {} {}. Assigning atom element "
+ "from Chemical Component Dictionary information", fullname.trim(), pdbnumber);
} else {
try {
element = Element.valueOfIgnoreCase(elementSymbol);
guessElement = false;
} catch (IllegalArgumentException e){
logger.warn("Element {} of atom {} {} was not recognised. Assigning atom element "
+ "from Chemical Component Dictionary information", elementSymbol,
fullname.trim(), pdbnumber);
}
}
} else {
// parse the name from the atom name
logger.warn("Missformatted PDB file: element column of atom {} {} is not present. "
+ "Assigning atom element from Chemical Component Dictionary information",
fullname.trim(), pdbnumber);
}
if (guessElement) {
String elementSymbol = null;
// for atom names with 4 characters, the element is
// at the first position, example HG23 in Valine
if (fullname.trim().length() == 4) {
elementSymbol = fullname.substring(0, 1);
} else if ( fullname.trim().length() > 1){
elementSymbol = fullname.substring(0, 2).trim();
}

try {
if (elementSymbol!=null)
if (currentGroup.getChemComp() != null) {
for (ChemCompAtom a : currentGroup.getChemComp().getAtoms()) {
if (a.getAtom_id().equals(fullname.trim())) {
elementSymbol = a.getType_symbol();
break;
}
}
if (elementSymbol == null) {
logger.warn("Atom name {} was not found in the Chemical Component Dictionary information of {}. "
+ "Assigning generic element R to it", fullname.trim(), currentGroup.getPDBName());
} else {
element = Element.valueOfIgnoreCase(elementSymbol);
} catch (IllegalArgumentException e){
logger.warn("Element {} was not recognised. Assigning generic element R to it", elementSymbol);
}
} else {
logger.warn("Chemical Component Dictionary information was not found for Atom name {}. "
+ "Assigning generic element R to it", fullname.trim());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment for this warning as for the others

}

}
atom.setElement(element);

Expand Down