001package com.hfg.bio;
002
003import java.util.HashSet;
004import java.util.Map;
005import java.util.Set;
006
007import com.hfg.chem.Charge;
008import com.hfg.chem.Element;
009import com.hfg.chem.IonizableGroup;
010import com.hfg.chem.Molecule;
011import com.hfg.xml.XMLNode;
012import com.hfg.util.StringUtil;
013
014//------------------------------------------------------------------------------
015/**
016 C-terminal protein group.
017 <div>
018  @author J. Alex Taylor, hairyfatguy.com
019 </div>
020 */
021//------------------------------------------------------------------------------
022// com.hfg XML/HTML Coding Library
023//
024// This library is free software; you can redistribute it and/or
025// modify it under the terms of the GNU Lesser General Public
026// License as published by the Free Software Foundation; either
027// version 2.1 of the License, or (at your option) any later version.
028//
029// This library is distributed in the hope that it will be useful,
030// but WITHOUT ANY WARRANTY; without even the implied warranty of
031// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
032// Lesser General Public License for more details.
033//
034// You should have received a copy of the GNU Lesser General Public
035// License along with this library; if not, write to the Free Software
036// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
037//
038// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
039// jataylor@hairyfatguy.com
040//------------------------------------------------------------------------------
041
042public class CTerminalGroup extends Molecule
043{
044   // This declaration has to come before the public constants below.
045   private static Set<CTerminalGroup> sValues = new HashSet<>(5);
046
047   //##########################################################################
048   // PUBLIC FIELDS
049   //##########################################################################
050
051   public static final CTerminalGroup UNMODIFIED_C_TERMINUS = new CTerminalGroup("Unmodified", "-OH");
052   public static final CTerminalGroup AMIDE                 = new CTerminalGroup("-amide", "-amide");
053   public static final CTerminalGroup O_METHYL              = new CTerminalGroup("-O-methyl", "-O-methyl");
054
055
056   static
057   {
058      UNMODIFIED_C_TERMINUS
059            .addAtoms(Element.HYDROGEN, 1)
060            .addAtoms(Element.OXYGEN, 1)
061            .addKa(new IonizableGroup(1.0E-3, Charge.NEUTRAL))  // pKa 3.0
062            .lock()
063            .register();
064
065      AMIDE.addAtoms(Element.HYDROGEN, 2)
066            .addAtoms(Element.NITROGEN, 1)
067            .lock()
068            .register();
069
070      O_METHYL
071            .addAtoms(Element.CARBON, 1)
072            .addAtoms(Element.HYDROGEN, 3)
073            .addAtoms(Element.OXYGEN, 1)
074            .lock()
075            .register();
076   }
077
078   //##########################################################################
079   // PRIVATE FIELDS
080   //##########################################################################
081
082   private String     mShortName;
083
084   //##########################################################################
085   // CONSTRUCTORS
086   //##########################################################################
087
088   //--------------------------------------------------------------------------
089   public CTerminalGroup(String inName)
090   {
091      super();
092      setName(inName);
093   }
094
095   //--------------------------------------------------------------------------
096   private CTerminalGroup(String inName, String inShortName)
097   {
098      this(inName);
099      mShortName = inShortName;
100   }
101
102   //--------------------------------------------------------------------------
103   public CTerminalGroup(String inName, Map inElementalComposition)
104   {
105      super(inName, inElementalComposition);
106   }
107
108   //--------------------------------------------------------------------------
109   public CTerminalGroup(XMLNode inXML)
110   {
111      super(inXML);
112
113      if (! inXML.getTagName().equals(HfgBioXML.CTERM_TAG))
114      {
115         throw new RuntimeException("Cannot construct an " + this.getClass().getSimpleName() + " from a " + inXML.getTagName() + " tag!");
116      }
117
118      XMLNode sidechainKasTag = inXML.getOptionalSubtagByName(HfgBioXML.SIDECHAIN_KAS_TAG);
119      if (sidechainKasTag != null)
120      {
121         for (XMLNode subtag : sidechainKasTag.getXMLNodeSubtags())
122         {
123            addKa(new IonizableGroup(subtag));
124         }
125      }
126
127
128      mShortName = inXML.getAttributeValue(HfgBioXML.SHORT_NAME_ATT);
129   }
130
131   //##########################################################################
132   // PUBLIC METHODS
133   //##########################################################################
134
135   //--------------------------------------------------------------------------
136   public static CTerminalGroup[] values()
137   {
138      return sValues.toArray(new CTerminalGroup[sValues.size()]);
139   }
140
141   //--------------------------------------------------------------------------
142   /**
143    Returns the CTerminalGroup whose name matches the specified String.
144    @param inString the name for the CTerminalGroup to retrieve
145    @return the CTerminalGroup whose name matches the specified String
146    */
147   public static CTerminalGroup valueOf(String inString)
148   {
149      CTerminalGroup value = null;
150
151      if (StringUtil.isSet(inString))
152      {
153         for (CTerminalGroup group : sValues)
154         {
155            if (group.name().equalsIgnoreCase(inString))
156            {
157               value = group;
158               break;
159            }
160         }
161      }
162
163      return value;
164   }
165
166   //--------------------------------------------------------------------------
167   /**
168    Puts the CTerminalGroup into the Set of unique CTerminalGroup returned by CTerminalGroup.values().
169    */
170   public void register()
171   {
172      if (! isLocked())
173      {
174         throw new RuntimeException("Only locked CTerminalGroups can be added to the values list!");
175      }
176
177      sValues.add(this);
178   }
179
180   //--------------------------------------------------------------------------
181   @Override
182   public CTerminalGroup addAtoms(Element inElement, int inNum)
183   {
184      return (CTerminalGroup) super.addAtoms(inElement, inNum);
185   }
186
187   //--------------------------------------------------------------------------
188   @Override
189   public CTerminalGroup lock()
190   {
191      return (CTerminalGroup) super.lock();
192   }
193
194
195   //--------------------------------------------------------------------------
196   @Override
197   public CTerminalGroup addKa(IonizableGroup inValue)
198   {
199      return (CTerminalGroup) super.addKa(inValue);
200   }
201
202   //--------------------------------------------------------------------------
203   public String getShortName()
204   {
205      return mShortName;
206   }
207
208
209   //--------------------------------------------------------------------------
210   @Override
211   public XMLNode toXMLNode()
212   {
213      XMLNode node = super.toXMLNode();
214      node.setTagName(HfgBioXML.CTERM_TAG);
215
216      if (StringUtil.isSet(mShortName)) node.setAttribute(HfgBioXML.SHORT_NAME_ATT, mShortName);
217
218      return node;
219   }
220
221
222}