1 package jalview.structure;
3 import jalview.datamodel.SequenceI;
4 import jalview.io.StructureFile;
5 import jalview.structures.models.MappingOutputModel;
7 import java.util.ArrayList;
8 import java.util.Collection;
11 import java.util.Map.Entry;
14 import MCview.PDBChain;
16 public abstract class StructureMappingClient
18 protected StructureFile structureFile;
20 private static final int PDB_RES_POS = StructureMapping.PDB_RES_NUM_INDEX; // 0
22 private static final int PDB_ATOM_POS = StructureMapping.PDB_ATOM_NUM_INDEX; // 1
25 * Populates the atom positions mapped to by finding the atom number (if any)
26 * for each structure residue number in the map. If no atom is found (as is
27 * the case for residues missing in a PDB file), then deletes the residue from
32 * @throws IllegalArgumentException
33 * @throws StructureMappingException
35 public void populateAtomPositions(String chainId,
36 Map<Integer, int[]> mapping) throws IllegalArgumentException,
37 StructureMappingException
41 PDBChain chain = structureFile.findChain(chainId);
43 if (chain == null || mapping == null)
45 throw new IllegalArgumentException(
46 "Chain id or mapping must not be null.");
49 List<Integer> notFound = new ArrayList<Integer>();
50 for (Entry<Integer, int[]> map : mapping.entrySet())
52 int structureResNo = map.getValue()[PDB_RES_POS];
55 * find the atom number in the chain for this residue number
56 * NB only CA or P atoms have been saved in the chain - see
57 * JmolParser.convertSignificantAtoms
59 int atomIndex = getAtomIndex(structureResNo, chain.atoms);
60 if (atomIndex == StructureMapping.UNASSIGNED)
62 notFound.add(map.getKey());
66 map.getValue()[PDB_ATOM_POS] = atomIndex;
69 for (Integer missing : notFound)
71 mapping.remove(missing);
75 throw new StructureMappingException(
76 "Structure mapping exception occured.");
83 * The residue index used for the search
85 * A collection of Atom to search
86 * @return atom position for the given residue index
88 public int getAtomIndex(int residueIndex, Collection<Atom> atoms)
92 throw new IllegalArgumentException(
93 "atoms collection must not be null!");
95 for (Atom atom : atoms)
97 if (atom.resNumber == residueIndex)
99 return atom.atomIndex;
102 return StructureMapping.UNASSIGNED;
105 public class StructureMappingException extends Exception
108 private static final long serialVersionUID = 1L;
110 public StructureMappingException(String message)
119 * sequence to generate mapping against the structure
121 * PDB file for the mapping
123 * the chain of the entry to use for mapping
124 * @return StructureMapping
127 public abstract StructureMapping getStructureMapping(SequenceI seq,
128 String pdbFile, String chain) throws Exception,
129 StructureMappingException;
135 * @return Sequence<->Structure mapping as int[][]
136 * @throws StructureMappingException
138 public abstract StringBuffer getMappingOutput(MappingOutputModel mp)
139 throws StructureMappingException;