1 /* 2 * Copyright (c) 2016 John May <jwmay@users.sf.net> 3 * 4 * Contact: cdk-devel@lists.sourceforge.net 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU Lesser General Public License as published by 8 * the Free Software Foundation; either version 2.1 of the License, or (at 9 * your option) any later version. All we ask is that proper credit is given 10 * for our work, which includes - but is not limited to - adding the above 11 * copyright notice to the beginning of your source code files, and to any 12 * copyright notice that you may distribute with programs based on this work. 13 * 14 * This program is distributed in the hope that it will be useful, but WITHOUT 15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17 * License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 U 22 */ 23 package org.openscience.cdk.isomorphism.matchers.smarts; 24 25 import org.openscience.cdk.CDKConstants; 26 import org.openscience.cdk.ReactionRole; 27 import org.openscience.cdk.interfaces.IAtom; 28 import org.openscience.cdk.interfaces.IChemObjectBuilder; 29 30 /** 31 * Matches atoms with a particular role in a reaction. 32 */ 33 @Deprecated 34 public class ReactionRoleQueryAtom extends SMARTSAtom { 35 36 public static final int ROLE_REACTANT = 0x1; 37 public static final int ROLE_AGENT = 0x2; 38 public static final int ROLE_PRODUCT = 0x4; 39 public static final int ROLE_ANY = ROLE_REACTANT | ROLE_PRODUCT | ROLE_AGENT; 40 41 private final int role; 42 43 public final static ReactionRoleQueryAtom RoleReactant = new ReactionRoleQueryAtom(null, ROLE_REACTANT); 44 public final static ReactionRoleQueryAtom RoleAgent = new ReactionRoleQueryAtom(null, ROLE_AGENT); 45 public final static ReactionRoleQueryAtom RoleProduct = new ReactionRoleQueryAtom(null, ROLE_PRODUCT); 46 ReactionRoleQueryAtom(IChemObjectBuilder builder, int role)47 public ReactionRoleQueryAtom(IChemObjectBuilder builder, int role) { 48 super(builder); 49 this.role = role; 50 } 51 52 @Override matches(IAtom atom)53 public boolean matches(IAtom atom) { 54 ReactionRole atomRole = atom.getProperty(CDKConstants.REACTION_ROLE); 55 if (atomRole == null) 56 return this.role == ROLE_ANY; 57 switch (atomRole) { 58 case Reactant: 59 return (this.role & ROLE_REACTANT) != 0; 60 case Agent: 61 return (this.role & ROLE_AGENT) != 0; 62 case Product: 63 return (this.role & ROLE_PRODUCT) != 0; 64 default: 65 return false; 66 } 67 } 68 69 @Override toString()70 public String toString() { 71 StringBuilder sb = new StringBuilder(); 72 if ((role & ROLE_REACTANT) != 0) 73 sb.append("Reactant"); 74 if ((role & ROLE_AGENT) != 0) 75 sb.append("Agent"); 76 if ((role & ROLE_PRODUCT) != 0) 77 sb.append("Product"); 78 return "ReactionRole(" + sb.toString() + ")"; 79 } 80 } 81