001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021package org.biojava.nbio.structure.domain;
022
023import java.io.IOException;
024import java.util.List;
025import java.util.regex.Matcher;
026import java.util.regex.Pattern;
027
028import org.biojava.nbio.structure.ResidueRange;
029import org.biojava.nbio.structure.Structure;
030import org.biojava.nbio.structure.StructureException;
031import org.biojava.nbio.structure.StructureIdentifier;
032import org.biojava.nbio.structure.SubstructureIdentifier;
033import org.biojava.nbio.structure.align.util.AtomCache;
034
035public class PDPDomain implements StructureIdentifier {
036        private static final long serialVersionUID = 6894463080739943026L;
037        
038        private String identifier;
039        private SubstructureIdentifier canonical;
040        
041        public static final Pattern PDP_NAME_PATTERN = Pattern.compile("^(?:PDP:)([0-9][a-z0-9]{3})(\\w)(\\w)$",Pattern.CASE_INSENSITIVE);
042
043        public PDPDomain(String pdpDomainName, List<ResidueRange> ranges) {
044                this.identifier = pdpDomainName;
045                Matcher matcher = PDP_NAME_PATTERN.matcher(identifier);
046                if(!matcher.matches()) {
047                        throw new IllegalArgumentException("Malformed PDP domain name");
048                }
049                String pdbId = matcher.group(1);
050                this.canonical = new SubstructureIdentifier(pdbId,ranges);
051        }
052
053        @Override
054        public String getIdentifier() {
055                return identifier;
056        }
057
058        public String getPdbId() {
059                return canonical.getPdbId();
060        }
061
062        @Override
063        public SubstructureIdentifier toCanonical() {
064                return canonical;
065        }
066
067        @Override
068        public Structure reduce(Structure input) throws StructureException {
069                return canonical.reduce(input);
070        }
071
072        @Override
073        public String toString() {
074                return getIdentifier();
075        }
076
077        @Override
078        public Structure loadStructure(AtomCache cache) throws StructureException,
079                        IOException {
080                return canonical.loadStructure(cache);
081        }
082}