--- /dev/null
+package jalview.structure;
+
+import jalview.datamodel.SequenceI;
+import jalview.io.StructureFile;
+import jalview.structures.models.MappingOutputModel;
+
+import java.util.Collection;
+import java.util.Map;
+
+import MCview.Atom;
+import MCview.PDBChain;
+
+public abstract class StructureMappingClient
+{
+
+ protected StructureFile structureFile;
+
+ public static final int UNASSIGNED = -1;
+
+ private static final int PDB_RES_POS = 0;
+
+ private static final int PDB_ATOM_POS = 1;
+
+ public void populateAtomPositions(String chainId,
+ Map<Integer, int[]> mapping)
+ throws IllegalArgumentException,
+ StructureMappingException
+ {
+ try
+ {
+ PDBChain chain = structureFile.findChain(chainId);
+
+ if (chain == null || mapping == null)
+ {
+ throw new IllegalArgumentException(
+ "Chain id or mapping must not be null.");
+ }
+ for (int[] map : mapping.values())
+ {
+ if (map[PDB_RES_POS] != UNASSIGNED)
+ {
+ map[PDB_ATOM_POS] = getAtomIndex(map[PDB_RES_POS], chain.atoms);
+ }
+ }
+ } catch (Exception e)
+ {
+ throw new StructureMappingException(
+ "Structure mapping exception occured.");
+ }
+ }
+
+ /**
+ *
+ * @param residueIndex
+ * The residue index used for the search
+ * @param atoms
+ * A collection of Atom to search
+ * @return atom position for the given residue index
+ */
+ public int getAtomIndex(int residueIndex, Collection<Atom> atoms)
+ {
+ if (atoms == null)
+ {
+ throw new IllegalArgumentException(
+ "atoms collection must not be null!");
+ }
+ for (Atom atom : atoms)
+ {
+ if (atom.resNumber == residueIndex)
+ {
+ return atom.atomIndex;
+ }
+ }
+ return UNASSIGNED;
+ }
+
+ public class StructureMappingException extends Exception
+ {
+
+ private static final long serialVersionUID = 1L;
+
+ public StructureMappingException(String message)
+ {
+ super(message);
+ }
+ }
+
+ /**
+ *
+ * @param seq
+ * sequence to generate mapping against the structure
+ * @param pdbFile
+ * PDB file for the mapping
+ * @param chain
+ * the chain of the entry to use for mapping
+ * @return StructureMapping
+ * @throws Exception
+ */
+ public abstract StructureMapping getStructureMapping(SequenceI seq,
+ String pdbFile, String chain) throws Exception,
+ StructureMappingException;
+
+ /**
+ *
+ * @param mop
+ * MappingOutputPojo
+ * @return Sequence<->Structure mapping as int[][]
+ * @throws StructureMappingException
+ */
+ public abstract StringBuffer getMappingOutput(MappingOutputModel mp)
+ throws StructureMappingException;
+
+}