AcylAlkylGroup.java

  1. /*
  2.  * Copyright 2021 Dominik Kopczynski, Nils Hoffmann.
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *      http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */
  16. package org.lifstools.jgoslin.domain;

  17. import java.util.ArrayList;

  18. /**
  19.  * An acyl alkyl group as a functional group.
  20.  *
  21.  * @author Dominik Kopczynski
  22.  * @author Nils Hoffmann
  23.  */
  24. public final class AcylAlkylGroup extends FunctionalGroup {

  25.     private boolean alkyl;
  26.     private boolean nitrogenBond;

  27.     public AcylAlkylGroup(FattyAcid _fa, KnownFunctionalGroups knownFunctionalGroups) {
  28.         this(_fa, -1, 1, false, false, knownFunctionalGroups);
  29.     }

  30.     public AcylAlkylGroup(FattyAcid _fa, int _position, int _count, boolean _alkyl, KnownFunctionalGroups knownFunctionalGroups) {
  31.         this(_fa, _position, _count, _alkyl, false, knownFunctionalGroups);
  32.     }

  33.     public AcylAlkylGroup(FattyAcid _fa, int _position, int _count, boolean _alkyl, boolean _N_bond, KnownFunctionalGroups knownFunctionalGroups) {
  34.         super("O", _position, _count, knownFunctionalGroups);
  35.         alkyl = _alkyl;
  36.         if (_fa != null) {
  37.             String key = (alkyl ? "alkyl" : "acyl");
  38.             functionalGroups.put(key, new ArrayList<>());
  39.             functionalGroups.get(key).add(_fa);
  40.         }
  41.         doubleBonds.setNumDoubleBonds(alkyl ? 0 : 1);
  42.         setNitrogenBond(_N_bond);

  43.     }

  44.     @Override
  45.     public FunctionalGroup copy() {
  46.         String key = alkyl ? "alkyl" : "acyl";
  47.         return new AcylAlkylGroup((FattyAcid) functionalGroups.get(key).get(0).copy(), getPosition(), getCount(), alkyl, nitrogenBond, knownFunctionalGroups);
  48.     }

  49.     public void setAlkyl(boolean alkyl) {
  50.         this.alkyl = alkyl;
  51.     }

  52.     public boolean isAlkyl() {
  53.         return this.alkyl;
  54.     }

  55.     public void setNitrogenBond(boolean _N_bond) {
  56.         nitrogenBond = _N_bond;

  57.         if (nitrogenBond) {
  58.             elements.put(Element.H, (alkyl ? 2 : 0));
  59.             elements.put(Element.O, (alkyl ? -1 : 0));
  60.             elements.put(Element.N, 1);
  61.         } else {
  62.             elements.put(Element.H, (alkyl ? 1 : -1));
  63.             elements.put(Element.O, (alkyl ? 0 : 1));
  64.         }
  65.     }

  66.     public boolean isNitrogenBond() {
  67.         return this.nitrogenBond;
  68.     }

  69.     @Override
  70.     public String toString(LipidLevel level) {
  71.         StringBuilder acyl_alkyl_string = new StringBuilder();
  72.         if (level == LipidLevel.FULL_STRUCTURE) {
  73.             acyl_alkyl_string.append(getPosition());
  74.         }
  75.         acyl_alkyl_string.append(nitrogenBond ? "N" : "O").append("(");
  76.         if (!alkyl) {
  77.             acyl_alkyl_string.append("FA ");
  78.         }
  79.         String key = alkyl ? "alkyl" : "acyl";
  80.         acyl_alkyl_string.append(((FattyAcid) functionalGroups.get(key).get(0)).toString(level)).append(")");

  81.         return acyl_alkyl_string.toString();
  82.     }

  83. }