001package org.biojava.nbio.structure.chem; 002 003import java.io.Serializable; 004import java.util.Arrays; 005import java.util.Collections; 006import java.util.HashMap; 007import java.util.HashSet; 008import java.util.Map; 009import java.util.Set; 010 011/** 012 * Enumerates the classification of polymers. 013 * This information is derived from the mmcif dictionary 014 * @author mulvaney 015 * @author Andreas Prlic 016 * @see <a href="http://mmcif.rcsb.org/dictionaries/mmcif_pdbx.dic/Items/_entity_poly.type.html">link into mmCIF dictionary</a> 017 * @since 1.7 018 */ 019public enum PolymerType implements Serializable { 020 /** 021 * polypeptide(L) 022 */ 023 peptide("polypeptide(L)"), 024 /** 025 * polypeptide(D) 026 */ 027 dpeptide("polypeptide(D)"), 028 /** 029 * polydeoxyribonucleotide 030 */ 031 dna("polydeoxyribonucleotide"), 032 /** 033 * polyribonucleotide 034 */ 035 rna("polyribonucleotide"), 036 /** 037 * polydeoxyribonucleotide/polyribonucleotide hybrid 038 */ 039 dnarna("polydeoxyribonucleotide/polyribonucleotide hybrid"), 040 /** 041 * polysaccharide(D) 042 */ 043 polysaccharide("polysaccharide(D)"), 044 /** 045 * polysaccharide(L) 046 */ 047 lpolysaccharide("polysaccharide(L)"), 048 /** 049 * other 050 */ 051 otherPolymer("other"), 052 /** 053 * cyclic peptides 054 */ 055 cyclicPeptide("cyclic-pseudo-peptide"), 056 /** 057 * Peptide nucleic acids 058 */ 059 peptideNucleicAcid("peptide nucleic acid"), 060 /** 061 * if all else fails... 062 */ 063 unknown(null); 064 065 static Map<String, PolymerType> lookupTable = new HashMap<>(); 066 067 static { 068 for (PolymerType polymerType : PolymerType.values()) { 069 if (polymerType == unknown) { 070 continue; 071 } 072 073 lookupTable.put(polymerType.entity_poly_type,polymerType); 074 lookupTable.put(polymerType.entity_poly_type.toLowerCase(), polymerType); 075 } 076 } 077 078 public final String entity_poly_type; 079 080 PolymerType(String entity_poly_type) { 081 this.entity_poly_type = entity_poly_type; 082 } 083 084 public static PolymerType polymerTypeFromString(String polymerTypeString) { 085 if (polymerTypeString.equalsIgnoreCase(peptide.entity_poly_type)) { 086 return peptide; 087 } 088 089 PolymerType lookedUpPolymerType = lookupTable.get(polymerTypeString); 090 if (lookedUpPolymerType != null) { 091 return lookedUpPolymerType; 092 } 093 094 lookedUpPolymerType = lookupTable.get(polymerTypeString.toLowerCase()); 095 if (lookedUpPolymerType != null) { 096 return lookedUpPolymerType; 097 } 098 099 for (PolymerType polymerType : PolymerType.values()) { 100 if (polymerTypeString.equals(polymerType.entity_poly_type)) { 101 return polymerType; 102 } 103 } 104 105 return unknown; 106 } 107 108 /** 109 * Convenience <tt>Set</tt> of polymer types classified as protein. This only contains {@link #peptide} 110 */ 111 public static final Set<PolymerType> PROTEIN_ONLY; 112 113 /** 114 * Convenience <tt>Set</tt> of polymer types classified as DNA. This only contains {@link #dna} 115 */ 116 public static final Set<PolymerType> DNA_ONLY; 117 118 /** 119 * Convenience <tt>Set</tt> of polymer types classified as RNA. This only contains {@link #rna} 120 */ 121 public static final Set<PolymerType> RNA_ONLY; 122 123 /** 124 * Convenience <tt>Set</tt> of polymer types classified as DNA. This contains: 125 * <ul> 126 * <li>{@link #dna}</li> 127 * <li>{@link #rna}</li> 128 * <li>{@link #dnarna}</li> 129 * </ul> 130 */ 131 public static final Set<PolymerType> POLYNUCLEOTIDE_ONLY; 132 133 /** 134 * Convenience <tt>Set</tt> of all polymer types. 135 */ 136 public static final Set<PolymerType> ALL_POLYMER_TYPES; 137 138 static { 139 Set<PolymerType> tmp; 140 141 tmp = new HashSet<>(); 142 tmp.add(peptide); 143 PROTEIN_ONLY = Collections.unmodifiableSet(tmp); 144 145 tmp = new HashSet<>(); 146 tmp.add(dna); 147 DNA_ONLY = Collections.unmodifiableSet(tmp); 148 149 tmp = new HashSet<>(); 150 tmp.add(rna); 151 RNA_ONLY = Collections.unmodifiableSet(tmp); 152 153 tmp = new HashSet<>(); 154 tmp.add(dna); 155 tmp.add(rna); 156 tmp.add(dnarna); 157 POLYNUCLEOTIDE_ONLY = Collections.unmodifiableSet(tmp); 158 159 ALL_POLYMER_TYPES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(values()))); 160 } 161}