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 String identifier; 037 SubstructureIdentifier canonical; 038 public static final Pattern PDP_NAME_PATTERN = Pattern.compile("^(?:PDP:)([0-9][a-z0-9]{3})(\\w)(\\w)$",Pattern.CASE_INSENSITIVE); 039 040 public PDPDomain(String pdpDomainName, List<ResidueRange> ranges) { 041 this.identifier = pdpDomainName; 042 Matcher matcher = PDP_NAME_PATTERN.matcher(identifier); 043 if(!matcher.matches()) { 044 throw new IllegalArgumentException("Malformed PDP domain name"); 045 } 046 String pdbId = matcher.group(1); 047 this.canonical = new SubstructureIdentifier(pdbId,ranges); 048 } 049 050 @Override 051 public String getIdentifier() { 052 return identifier; 053 } 054 055 public String getPdbId() { 056 return canonical.getPdbId(); 057 } 058 059 @Override 060 public SubstructureIdentifier toCanonical() { 061 return canonical; 062 } 063 064 @Override 065 public Structure reduce(Structure input) throws StructureException { 066 return canonical.reduce(input); 067 } 068 069 @Override 070 public String toString() { 071 return getIdentifier(); 072 } 073 074 @Override 075 public Structure loadStructure(AtomCache cache) throws StructureException, 076 IOException { 077 return canonical.loadStructure(cache); 078 } 079}