@@ -167,6 +167,9 @@ public class StructureTools {
167167
168168 private static final Set <Element > hBondDonorAcceptors ;
169169
170+ private static final Set <String > NUCLEOTIDE_BACKBONE_ATOMS ;
171+ private static final Set <String > AMINOACID_BACKBONE_ATOMS ;
172+
170173 static {
171174 nucleotides30 = new HashMap <String , Character >();
172175 nucleotides30 .put ("DA" , 'A' );
@@ -256,6 +259,9 @@ public class StructureTools {
256259 hBondDonorAcceptors .add (Element .O );
257260 hBondDonorAcceptors .add (Element .S );
258261
262+ NUCLEOTIDE_BACKBONE_ATOMS = new HashSet <>(Arrays .asList (C1_ATOM_NAME , C2_ATOM_NAME , C3_ATOM_NAME , C4_ATOM_NAME , O2_ATOM_NAME , O3_ATOM_NAME , O4_ATOM_NAME , O5_ATOM_NAME , OP1_ATOM_NAME , OP2_ATOM_NAME , P_ATOM_NAME ));
263+ AMINOACID_BACKBONE_ATOMS = new HashSet <>(Arrays .asList (CA_ATOM_NAME , C_ATOM_NAME , N_ATOM_NAME , O_ATOM_NAME ));
264+
259265 }
260266
261267 /**
@@ -1128,65 +1134,36 @@ public static Atom[] getRepresentativeAtomArray(Structure s) {
11281134 * @return an Atom[] array
11291135 */
11301136 public static Atom [] getBackboneAtomArray (Structure s ) {
1131-
11321137 List <Atom > atoms = new ArrayList <>();
1133-
11341138 for (Chain c : s .getChains ()) {
11351139 for (Group g : c .getAtomGroups ()) {
11361140 if (g .hasAminoAtoms ()) {
1137- // this means we will only take atoms grom groups that have
1138- // complete backbones
1139- for (Atom a : g .getAtoms ()) {
1140- switch (g .getType ()) {
1141- case NUCLEOTIDE :
1142- // Nucleotide backbone
1143- if (a .getName ().equals (C1_ATOM_NAME ))
1144- atoms .add (a );
1145- if (a .getName ().equals (C2_ATOM_NAME ))
1146- atoms .add (a );
1147- if (a .getName ().equals (C3_ATOM_NAME ))
1148- atoms .add (a );
1149- if (a .getName ().equals (C4_ATOM_NAME ))
1150- atoms .add (a );
1151- if (a .getName ().equals (O2_ATOM_NAME ))
1152- atoms .add (a );
1153- if (a .getName ().equals (O3_ATOM_NAME ))
1154- atoms .add (a );
1155- if (a .getName ().equals (O4_ATOM_NAME ))
1156- atoms .add (a );
1157- if (a .getName ().equals (O5_ATOM_NAME ))
1158- atoms .add (a );
1159- if (a .getName ().equals (OP1_ATOM_NAME ))
1160- atoms .add (a );
1161- if (a .getName ().equals (OP2_ATOM_NAME ))
1162- atoms .add (a );
1163- if (a .getName ().equals (P_ATOM_NAME ))
1164- atoms .add (a );
1165- // TODO Allow C4* names as well as C4'? -SB 3/2015
1166- break ;
1167- case AMINOACID :
1168- default :
1169- // we do it this way instead of with g.getAtom() to
1170- // be sure we always use the same order as original
1171- if (a .getName ().equals (CA_ATOM_NAME ))
1172- atoms .add (a );
1173- if (a .getName ().equals (C_ATOM_NAME ))
1174- atoms .add (a );
1175- if (a .getName ().equals (N_ATOM_NAME ))
1176- atoms .add (a );
1177- if (a .getName ().equals (O_ATOM_NAME ))
1178- atoms .add (a );
1179- break ;
1180- }
1141+ if (g .getType () == GroupType .NUCLEOTIDE ) {
1142+ addNucleotideAndAminoAtoms (atoms , g , NUCLEOTIDE_BACKBONE_ATOMS );
1143+ } else {
1144+ addNucleotideAndAminoAtoms (atoms , g , AMINOACID_BACKBONE_ATOMS );
11811145 }
11821146 }
11831147 }
1184-
11851148 }
1186-
11871149 return atoms .toArray (new Atom [0 ]);
11881150 }
11891151
1152+ /**
1153+ * This method will be used to add the Nucleotide and Amino atoms to the backbone Atom arrays based on the pre-defined Atom names.
1154+ * @param atoms
1155+ * @param g
1156+ * @param atomNames
1157+ */
1158+ private static void addNucleotideAndAminoAtoms (List <Atom > atoms , Group g , Set <String > atomNames ) {
1159+ for (Atom a : g .getAtoms ()) {
1160+ if (atomNames .contains (a .getName ())) {
1161+ atoms .add (a );
1162+ }
1163+ }
1164+ }
1165+
1166+
11901167 /**
11911168 * Convert three character amino acid codes into single character e.g.
11921169 * convert CYS to C. Valid 3-letter codes will be those of the standard 20
0 commit comments