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 java.util.HashMap;
024import java.util.Set;
025
026/**
027 *
028 * An enum to represent the experimental technique of a PDB structure
029 *
030 * @author duarte_j
031 *
032 */
033public enum ExperimentalTechnique {
034
035
036         XRAY_DIFFRACTION                       ("X-RAY DIFFRACTION",           true,   false),
037
038         SOLUTION_NMR                           ("SOLUTION NMR",                        false,  true),
039         SOLID_STATE_NMR                        ("SOLID-STATE NMR",                     false,  true),
040
041         ELECTRON_MICROSCOPY            ("ELECTRON MICROSCOPY",         false,  false),
042         ELECTRON_CRYSTALLOGRAPHY       ("ELECTRON CRYSTALLOGRAPHY",true,       false),
043
044         FIBER_DIFFRACTION                      ("FIBER DIFFRACTION",           false,  false),
045
046         NEUTRON_DIFFRACTION            ("NEUTRON DIFFRACTION",         true,   false),
047
048         SOLUTION_SCATTERING            ("SOLUTION SCATTERING",         false,  false),
049
050
051         // from here, not in "official list" in pdb.org advanced search: they call these "OTHER"
052         POWDER_DIFFRACTION                     ("POWDER DIFFRACTION",          true,   false),
053
054         FLUORESCENCE_TRANSFER          ("FLUORESCENCE TRANSFER",       false,  false),
055
056         INFRARED_SPECTROSCOPY          ("INFRARED SPECTROSCOPY",       false,  false);
057
058
059         private static final HashMap<String, ExperimentalTechnique> expTechStr2Value = initExpTechStr2Value();
060
061
062         private String name;
063         private boolean isCrystallographic;
064         private boolean isNmr;
065
066         private ExperimentalTechnique(String name, boolean isXtallographic, boolean isNmr) {
067                 this.name = name;
068                 this.isCrystallographic = isXtallographic;
069                 this.isNmr = isNmr;
070         }
071
072
073         private static HashMap<String, ExperimentalTechnique> initExpTechStr2Value() {
074                HashMap<String, ExperimentalTechnique> expTechStr2Value = new HashMap<String, ExperimentalTechnique>();
075                for(ExperimentalTechnique exp:ExperimentalTechnique.values()) {
076                        expTechStr2Value.put(exp.getName(), exp);
077                }
078                return expTechStr2Value;
079         }
080
081         public String getName() {
082                 return name;
083         }
084
085         public boolean isCrystallographic() {
086                 return isCrystallographic;
087         }
088
089         public boolean isNmr() {
090                 return isNmr;
091         }
092
093         /**
094          * Returns the ExpTechnique given an experimental technique name as used in the PDB,
095          * e.g. "X-RAY DIFFRACTION" returns {@link ExperimentalTechnique#XRAY_DIFFRACTION}
096          * @param expTechniqueName the ExpTechnique value or null if string doesn't match one of the known PDB experimental strings
097          * @return
098          */
099         public static ExperimentalTechnique getByName(String expTechniqueName) {
100                 return expTechStr2Value.get(expTechniqueName);
101         }
102
103         /**
104          * Given a Set of ExperimentalTechniques returns true if at least one is crystallographic
105          * @return true if at least 1 of the techniques is crystallographic, false if
106          * none of the techniques are crystallographic
107          * @throws NullPointerException if input is null
108          */
109         public static boolean isCrystallographic(Set<ExperimentalTechnique> techniques) {
110
111                 for (ExperimentalTechnique et:techniques) {
112                         if (et.isCrystallographic()) return true;
113                 }
114
115                 return false;
116
117         }
118
119         /**
120          * Given a Set of ExperimentalTechniques returns true if at least one is NMR
121          * @return true if at least 1 of the techniques is NMR, false if
122          * none of the techniques are NMR
123          * @throws NullPointerException if input is null
124          */
125         public static boolean isNmr(Set<ExperimentalTechnique> techniques) {
126
127                 for (ExperimentalTechnique et:techniques) {
128                         if (et.isNmr()) return true;
129                 }
130
131                 return false;
132         }
133
134         @Override
135        public String toString() {
136                 return getName();
137         }
138}