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;
022
023import org.biojava.nbio.structure.io.mmcif.chem.PolymerType;
024import org.biojava.nbio.structure.io.mmcif.chem.ResidueType;
025
026import java.util.*;
027
028
029/**
030 * This contains basic categories for Group types. It reflects the categorization
031 * used in old PDB file (e.g. for storing whether a residue is composed of
032 * ATOM or HETATM records. It is less specific than the mmCIF/PDBx-defined
033 * ResidueType enum, which may be more suitable for future applications.
034 *
035 * @author Andreas Prlic
036 * @author Spencer Bliven
037 * @since 1.7
038 * @see ResidueType
039 *
040 */
041public enum GroupType {
042
043
044        /**
045         * The type for amino acids (L-peptides)
046         */
047        AMINOACID("amino",GroupType.matchPolymerTypes(PolymerType.PROTEIN_ONLY)),
048
049        /**
050         * The type for nucleotide groups (dna and rna)
051         */
052        NUCLEOTIDE("nucleotide",GroupType.matchPolymerTypes(PolymerType.POLYNUCLEOTIDE_ONLY)),
053
054        /**
055         * The type for hetero groups (everything else)
056         */
057        HETATM("hetatm",GroupType.getHetatmTypes());
058
059        private final String name;
060        private final Set<ResidueType> types;
061        private GroupType(String name,Set<ResidueType> types) {
062                this.name = name;
063                this.types = types;
064        }
065
066        /**
067         * The 3-letter codes used in the PDB to identify water molecules
068         * @see Group#isWater()
069         */
070        public static final List<String> WATERNAMES = Arrays.asList("HOH", "DOD", "WAT");
071
072        /**
073         * @return The name of this GroupType. One of "amino", "nucleotide", or "hetatm"
074         */
075        @Override
076        public String toString() {
077                return name;
078        }
079
080        /**
081         * Get a set of ResidueTypes loosely equivalent to this GroupType.
082         *
083         * <p>Because mmCIF and PDB handle modified residues differently, some
084         * Groups may have a well-defined ResidueType yet still be HETATMs.
085         * @return A Set of ResidueTypes commonly classified as this GroupType
086         */
087        public Set<ResidueType> getResidueTypes() {
088                return types;
089        }
090
091        /**
092         * Get ResidueTypes whose polymerType is contained in a certain set.
093         * This is used for defining the AMINOACID and NUCLEOTIDE sets.
094         * @param allowedTypes
095         * @return
096         */
097        private static Set<ResidueType> matchPolymerTypes(Set<PolymerType> allowedTypes) {
098                Set<ResidueType> matched = new HashSet<ResidueType>();
099                for(ResidueType restype : ResidueType.values()) {
100                        if(allowedTypes.contains(restype.polymerType)) {
101                                matched.add(restype);
102                        }
103                }
104                return Collections.unmodifiableSet(matched);
105        }
106
107        /**
108         * Bundles everything not in AMINOACID or NUCLEOTIDE into the HETATM entry
109         * @return
110         */
111        private static Set<ResidueType> getHetatmTypes() {
112                Set<ResidueType> unmatched = new HashSet<ResidueType>();
113                for(ResidueType restype : ResidueType.values()) {
114                        if(!AMINOACID.getResidueTypes().contains(restype) &&
115                                        !NUCLEOTIDE.getResidueTypes().contains(restype) ) {
116                                unmatched.add(restype);
117                        }
118                }
119                return Collections.unmodifiableSet(unmatched);
120        }
121}