31
31
import java .io .StringReader ;
32
32
import java .util .ArrayList ;
33
33
import java .util .HashMap ;
34
+ import java .util .HashSet ;
34
35
import java .util .Hashtable ;
35
36
import java .util .List ;
36
37
import java .util .Map ;
38
+ import java .util .Set ;
37
39
38
40
import javax .vecmath .Point3d ;
39
41
@@ -108,6 +110,7 @@ public class PDBReader extends DefaultChemObjectReader {
108
110
* names; for example "RFB.N13" maps to "N.planar3".
109
111
*/
110
112
private Map <String , String > hetDictionary ;
113
+ private Set <String > hetResidues ;
111
114
112
115
private AtomTypeFactory cdkAtomTypeFactory ;
113
116
@@ -630,7 +633,7 @@ private PDBAtom readAtom(String cLine, int lineLength) throws CDKException {
630
633
throw new RuntimeException ("PDBReader error during readAtom(): line too short" );
631
634
}
632
635
633
- boolean isHetatm = cLine .substring ( 0 , 6 ). equals ("HETATM" );
636
+ boolean isHetatm = cLine .startsWith ("HETATM" );
634
637
String atomName = cLine .substring (12 , 16 ).trim ();
635
638
String resName = cLine .substring (17 , 20 ).trim ();
636
639
String symbol = parseAtomSymbol (cLine );
@@ -723,18 +726,27 @@ private String typeHetatm(String resName, String atomName) {
723
726
cdkAtomTypeFactory = AtomTypeFactory .getInstance ("org/openscience/cdk/dict/data/cdk-atom-types.owl" ,
724
727
DefaultChemObjectBuilder .getInstance ());
725
728
}
729
+
730
+ // lookup the atom type using the residue and name, if the atom is a hydrogen
731
+ // or carbon and is a known residue we default to the common H and C.sp2 cases
726
732
String key = resName + "." + atomName ;
727
- if (hetDictionary .containsKey (key )) {
728
- return hetDictionary .get (key );
729
- }
733
+ String type = hetDictionary .get (key );
734
+ if (type != null )
735
+ return type ;
736
+ else if (atomName .startsWith ("H" ))
737
+ return hetResidues .contains (resName ) ? "H" : null ;
738
+ else if (hetResidues .contains (resName ) && atomName .startsWith ("C" ))
739
+ return hetResidues .contains (resName ) ? "C.sp2" : null ;
740
+
730
741
return null ;
731
742
}
732
743
733
744
private void readHetDictionary () {
734
745
try {
735
746
InputStream ins = getClass ().getResourceAsStream (hetDictionaryPath );
736
747
BufferedReader bufferedReader = new BufferedReader (new InputStreamReader (ins ));
737
- hetDictionary = new HashMap <String , String >();
748
+ hetDictionary = new HashMap <>();
749
+ hetResidues = new HashSet <>();
738
750
String line ;
739
751
while ((line = bufferedReader .readLine ()) != null ) {
740
752
int colonIndex = line .indexOf (':' );
@@ -746,6 +758,7 @@ private void readHetDictionary() {
746
758
} else {
747
759
hetDictionary .put (typeKey , typeValue );
748
760
}
761
+ hetResidues .add (typeKey .split ("\\ ." )[0 ]);
749
762
}
750
763
bufferedReader .close ();
751
764
} catch (IOException ioe ) {
0 commit comments