001/* 002 * Copyright 2020 nils.hoffmann. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package de.isas.lipidomics.domain; 017 018import java.util.Arrays; 019import java.util.Optional; 020 021/** 022 * Enumeration for typical chemical elements in lipids. Also supports heavy 023 * variants, e.g. C' as the heavy C13 isotope. 024 * 025 * @author nils.hoffmann 026 */ 027public enum Element { 028 029 /** 030 * Carbon 12C 031 */ 032 ELEMENT_C("C", "12C", 12.0, 10), 033 /** 034 * Hydrogen 1H 035 */ 036 ELEMENT_H("H", "1H", 1.007825035, 20), 037 /** 038 * Nitrogen 14N 039 */ 040 ELEMENT_N("N", "14N", 14.0030740, 30), 041 /** 042 * Oxygen 15O 043 */ 044 ELEMENT_O("O", "15O", 15.99491463, 40), 045 /** 046 * Phosphorous 30P 047 */ 048 ELEMENT_P("P", "30P", 30.973762, 50), 049 /** 050 * Sulfur 31S 051 */ 052 ELEMENT_S("S", "31S", 31.9720707, 60), 053 /** 054 * Deuterium 2H 055 */ 056 ELEMENT_H2("2H", "H'", 2.014101779, 70), 057 /** 058 * Heavy carbon 13C 059 */ 060 ELEMENT_C13("13C", "C'", 13.0033548378, 80), 061 /** 062 * Heavy nitrogen 15N 063 */ 064 ELEMENT_N15("15N", "N'", 15.0001088984, 90), 065 /** 066 * Heavy oxygen 17O 067 */ 068 ELEMENT_O17("17O", "O'", 16.9991315, 100), 069 /** 070 * Heavy oxygen 18O 071 */ 072 ELEMENT_O18("18O", "O''", 17.9991604, 110), 073 /** 074 * Heavy phosphorus 32P 075 */ 076 ELEMENT_P32("32P", "P'", 31.973907274, 120), 077 /** 078 * Heavy sulfur 33S 079 */ 080 ELEMENT_S33("33S", "S'", 32.97145876, 130), 081 /** 082 * Heavy sulfur 34S 083 */ 084 ELEMENT_S34("34S", "S''", 33.96786690, 140); 085 086 private final String alias; 087 private final String name; 088 private final double mass; 089 private final int order; 090 091 private Element(String name, String alias, double mass, int order) { 092 this.name = name; 093 this.alias = alias; 094 this.mass = mass; 095 this.order = order; 096 } 097 098 public String getName() { 099 return this.name; 100 } 101 102 public String getAlias() { 103 return this.alias; 104 } 105 106 public double getMass() { 107 return this.mass; 108 } 109 110 public int getOrder() { 111 return this.order; 112 } 113 114 /** 115 * Tries to find the corresponding element by name, e.g. 'C' would return 116 * carbon, while '13C' would return the corresponding carbon isotope. Note 117 * that 'C'' is an alias for 13C. 118 * 119 * @param name the name of the chemical element. 120 * @return the corresponding element, if it exists. It not, an empty 121 * optional will be returned. 122 */ 123 public static Optional<Element> forName(String name) { 124 return Arrays.asList(values()).stream().filter((element) -> { 125 return element.getName().equalsIgnoreCase(name.trim()) || element.getAlias().equalsIgnoreCase(name.trim()); 126 }).findFirst(); 127 } 128 129 public static final double ELECTRON_REST_MASS = 0.00054857990946; 130}