com.hfg.bio.CTerminalGroup Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com_hfg Show documentation
Show all versions of com_hfg Show documentation
com.hfg xml, html, svg, and bioinformatics utility library
package com.hfg.bio;
import java.util.HashSet;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import com.hfg.chem.Charge;
import com.hfg.chem.Element;
import com.hfg.chem.IonizableGroup;
import com.hfg.chem.Molecule;
import com.hfg.exception.UnmodifyableObjectException;
import com.hfg.xml.XMLNode;
import com.hfg.xml.XMLTag;
import com.hfg.xml.XMLAttribute;
import com.hfg.util.collection.CollectionUtil;
import com.hfg.util.StringUtil;
//------------------------------------------------------------------------------
/**
C-terminal protein group.
@author J. Alex Taylor, hairyfatguy.com
*/
//------------------------------------------------------------------------------
// com.hfg XML/HTML Coding Library
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
// [email protected]
//------------------------------------------------------------------------------
public class CTerminalGroup extends Molecule
{
// This declaration has to come before the public constants below.
private static Set sValues = new HashSet<>();
//##########################################################################
// PUBLIC FIELDS
//##########################################################################
public static final CTerminalGroup UNMODIFIED_C_TERMINUS = new CTerminalGroup("Unmodified", "-OH");
public static final CTerminalGroup AMIDE = new CTerminalGroup("-amide", "-amide");
public static final CTerminalGroup O_METHYL = new CTerminalGroup("-O-methyl", "-O-methyl");
static
{
UNMODIFIED_C_TERMINUS
.addAtoms(Element.HYDROGEN, 1)
.addAtoms(Element.OXYGEN, 1)
.addKa(new IonizableGroup(1.0E-3, Charge.NEUTRAL)) // pKa 3.0
.lock()
.register();
AMIDE.addAtoms(Element.HYDROGEN, 2)
.addAtoms(Element.NITROGEN, 1)
.lock()
.register();
O_METHYL
.addAtoms(Element.CARBON, 1)
.addAtoms(Element.HYDROGEN, 3)
.addAtoms(Element.OXYGEN, 1)
.lock()
.register();
}
//##########################################################################
// PRIVATE FIELDS
//##########################################################################
private String mShortName;
private List mKas;
//##########################################################################
// CONSTRUCTORS
//##########################################################################
//--------------------------------------------------------------------------
public CTerminalGroup(String inName)
{
super(inName);
}
//--------------------------------------------------------------------------
private CTerminalGroup(String inName, String inShortName)
{
super(inName);
mShortName = inShortName;
}
//--------------------------------------------------------------------------
public CTerminalGroup(String inName, Map inElementalComposition)
{
super(inName, inElementalComposition);
}
//--------------------------------------------------------------------------
public CTerminalGroup(XMLNode inXML)
{
super(inXML.getAttributeValue(HfgBioXML.NAME_ATT));
if (! inXML.getTagName().equals(HfgBioXML.CTERM_TAG))
{
throw new RuntimeException("Cannot construct an " + this.getClass().getSimpleName() + " from a " + inXML.getTagName() + " tag!");
}
XMLNode sidechainKasTag = inXML.getOptionalSubtagByName(HfgBioXML.SIDECHAIN_KAS_TAG);
if (sidechainKasTag != null)
{
for (XMLNode subtag : sidechainKasTag.getXMLNodeSubtags())
{
addKa(new IonizableGroup(subtag));
}
}
mShortName = inXML.getAttributeValue(HfgBioXML.SHORT_NAME_ATT);
XMLNode compTag = inXML.getOptionalSubtagByName(HfgBioXML.ELEMENTAL_COMP_TAG);
if (compTag != null)
{
for (XMLAttribute attr : compTag.getAttributes())
{
addAtoms(Element.valueOf(attr.getName()), Float.parseFloat(attr.getValue()));
}
}
}
//##########################################################################
// PUBLIC METHODS
//##########################################################################
//--------------------------------------------------------------------------
public static CTerminalGroup[] values()
{
return sValues.toArray(new CTerminalGroup[sValues.size()]);
}
//--------------------------------------------------------------------------
/**
Returns the CTerminalGroup whose name matches the specified String.
@param inString the name for the CTerminalGroup to retrieve
@return the CTerminalGroup whose name matches the specified String
*/
public static CTerminalGroup valueOf(String inString)
{
CTerminalGroup value = null;
if (StringUtil.isSet(inString))
{
for (CTerminalGroup group : sValues)
{
if (group.name().equalsIgnoreCase(inString))
{
value = group;
break;
}
}
}
return value;
}
//--------------------------------------------------------------------------
/**
Puts the CTerminalGroup into the Set of unique CTerminalGroup returned by CTerminalGroup.values().
*/
public void register()
{
if (! isLocked())
{
throw new RuntimeException("Only locked CTerminalGroups can be added to the values list!");
}
sValues.add(this);
}
//--------------------------------------------------------------------------
@Override
public CTerminalGroup addAtoms(Element inElement, int inNum)
{
return (CTerminalGroup) super.addAtoms(inElement, inNum);
}
//--------------------------------------------------------------------------
@Override
public CTerminalGroup lock()
{
return (CTerminalGroup) super.lock();
}
//--------------------------------------------------------------------------
public CTerminalGroup addKa(IonizableGroup inValue)
{
if (isLocked()) throw new UnmodifyableObjectException(name() + " is locked and cannot be modified!");
if (null == mKas)
{
mKas = new ArrayList<>();
}
mKas.add(inValue);
return this;
}
//--------------------------------------------------------------------------
/**
Returns a List of IonizableGroup objects.
@return List of IonizableGroups on the C-terminal group
*/
public List getKas()
{
return mKas;
}
//--------------------------------------------------------------------------
public String getShortName()
{
return mShortName;
}
//--------------------------------------------------------------------------
@Override
public XMLNode toXMLNode()
{
XMLNode node = super.toXMLNode();
node.setTagName(HfgBioXML.CTERM_TAG);
if (CollectionUtil.hasValues(mKas))
{
XMLNode kasTag = new XMLTag(HfgBioXML.SIDECHAIN_KAS_TAG);
node.addSubtag(kasTag);
for (IonizableGroup grp : mKas)
{
kasTag.addSubtag(grp.toXMLNode());
}
}
if (StringUtil.isSet(mShortName)) node.setAttribute(HfgBioXML.SHORT_NAME_ATT, mShortName);
return node;
}
}