~ubuntu-branches/ubuntu/maverick/cdk/maverick

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/tools/manipulator/ReactionSetManipulator.java

  • Committer: Bazaar Package Importer
  • Author(s): Paul Cager
  • Date: 2008-04-09 21:17:53 UTC
  • Revision ID: james.westby@ubuntu.com-20080409211753-46lmjw5z8mx5pd8d
Tags: upstream-1.0.2
ImportĀ upstreamĀ versionĀ 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $RCSfile$
 
2
 * $Author: egonw $ 
 
3
 * $Date: 2006-07-31 11:23:24 +0200 (Mon, 31 Jul 2006) $
 
4
 * $Revision: 6710 $
 
5
 * 
 
6
 * Copyright (C) 2003-2007  The Chemistry Development Kit (CDK) project
 
7
 * 
 
8
 * Contact: cdk-devel@lists.sourceforge.net
 
9
 * 
 
10
 * This program is free software; you can redistribute it and/or
 
11
 * modify it under the terms of the GNU Lesser General Public License
 
12
 * as published by the Free Software Foundation; either version 2.1
 
13
 * of the License, or (at your option) any later version.
 
14
 * All we ask is that proper credit is given for our work, which includes
 
15
 * - but is not limited to - adding the above copyright notice to the beginning
 
16
 * of your source code files, and to any copyright notice that you may distribute
 
17
 * with programs based on this work.
 
18
 * 
 
19
 * This program is distributed in the hope that it will be useful,
 
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
 * GNU Lesser General Public License for more details.
 
23
 * 
 
24
 * You should have received a copy of the GNU Lesser General Public License
 
25
 * along with this program; if not, write to the Free Software
 
26
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
27
 *  */
 
28
package org.openscience.cdk.tools.manipulator;
 
29
 
 
30
import java.util.ArrayList;
 
31
import java.util.List;
 
32
 
 
33
import org.openscience.cdk.interfaces.IAtom;
 
34
import org.openscience.cdk.interfaces.IAtomContainer;
 
35
import org.openscience.cdk.interfaces.IBond;
 
36
import org.openscience.cdk.interfaces.IElectronContainer;
 
37
import org.openscience.cdk.interfaces.IMoleculeSet;
 
38
import org.openscience.cdk.interfaces.IReaction;
 
39
import org.openscience.cdk.interfaces.IReactionSet;
 
40
 
 
41
/**
 
42
 * @cdk.module standard
 
43
 *
 
44
 * @see ChemModelManipulator
 
45
 */
 
46
public class ReactionSetManipulator {
 
47
    
 
48
    public static int getAtomCount(IReactionSet set) {
 
49
        int count = 0;
 
50
        for (java.util.Iterator iter = set.reactions(); iter.hasNext();) {
 
51
                count += ReactionManipulator.getAtomCount((IReaction)iter.next());
 
52
        }
 
53
        return count;
 
54
    }
 
55
 
 
56
    public static int getBondCount(IReactionSet set) {
 
57
        int count = 0;
 
58
        for (java.util.Iterator iter = set.reactions(); iter.hasNext();) {
 
59
                count += ReactionManipulator.getBondCount((IReaction)iter.next());
 
60
        }
 
61
        return count;
 
62
    }
 
63
 
 
64
    public static void removeAtomAndConnectedElectronContainers(IReactionSet set, IAtom atom) {
 
65
        for (java.util.Iterator iter = set.reactions(); iter.hasNext();) {
 
66
            IReaction reaction = (IReaction)iter.next();
 
67
            ReactionManipulator.removeAtomAndConnectedElectronContainers(reaction, atom);
 
68
        }
 
69
    }
 
70
    
 
71
    public static void removeElectronContainer(IReactionSet set, IElectronContainer electrons) {
 
72
        for (java.util.Iterator iter = set.reactions(); iter.hasNext();) {
 
73
            IReaction reaction = (IReaction)iter.next();
 
74
            ReactionManipulator.removeElectronContainer(reaction, electrons);
 
75
        }
 
76
    }
 
77
    
 
78
    public static IMoleculeSet getAllMolecules(IReactionSet set) {
 
79
        IMoleculeSet moleculeSet = set.getBuilder().newMoleculeSet();
 
80
        for (java.util.Iterator iter = set.reactions(); iter.hasNext();) {
 
81
            IReaction reaction = (IReaction)iter.next();
 
82
            moleculeSet.add(ReactionManipulator.getAllMolecules(reaction));
 
83
        }
 
84
        return moleculeSet;
 
85
    }
 
86
    
 
87
    public static List getAllIDs(IReactionSet set) {
 
88
        List IDlist = new ArrayList();
 
89
        if (set.getID() != null) IDlist.add(set.getID());
 
90
        for (java.util.Iterator iter = set.reactions(); iter.hasNext();) {
 
91
            IReaction reaction = (IReaction)iter.next();
 
92
            IDlist.addAll(ReactionManipulator.getAllIDs(reaction));
 
93
        }
 
94
        return IDlist;
 
95
    }
 
96
    
 
97
    /**
 
98
     * Returns all the AtomContainer's of a Reaction.
 
99
     */
 
100
    public static List getAllAtomContainers(IReactionSet set) {
 
101
        
 
102
                return MoleculeSetManipulator.getAllAtomContainers(
 
103
            getAllMolecules(set)
 
104
        );
 
105
    }
 
106
    
 
107
    public static IReaction getRelevantReaction(IReactionSet set, IAtom atom) {
 
108
        for (java.util.Iterator iter = set.reactions(); iter.hasNext();) {
 
109
            IReaction reaction = (IReaction)iter.next();
 
110
            IAtomContainer container = ReactionManipulator.getRelevantAtomContainer(reaction, atom);
 
111
            if (container != null) { // a match!
 
112
                return reaction;
 
113
            }
 
114
        }
 
115
        return null;
 
116
    }
 
117
 
 
118
    public static IReaction getRelevantReaction(IReactionSet set, IBond bond) {
 
119
        for (java.util.Iterator iter = set.reactions(); iter.hasNext();) {
 
120
            IReaction reaction = (IReaction)iter.next();
 
121
            IAtomContainer container = ReactionManipulator.getRelevantAtomContainer(reaction, bond);
 
122
            if (container != null) { // a match!
 
123
                return reaction;
 
124
            }
 
125
        }
 
126
        return null;
 
127
    }
 
128
 
 
129
    public static IAtomContainer getRelevantAtomContainer(IReactionSet set, IAtom atom) {
 
130
        for (java.util.Iterator iter = set.reactions(); iter.hasNext();) {
 
131
            IReaction reaction = (IReaction)iter.next();
 
132
            IAtomContainer container = ReactionManipulator.getRelevantAtomContainer(reaction, atom);
 
133
            if (container != null) { // a match!
 
134
                return container;
 
135
            }
 
136
        }
 
137
        return null;
 
138
    }
 
139
 
 
140
    public static IAtomContainer getRelevantAtomContainer(IReactionSet set, IBond bond) {
 
141
        for (java.util.Iterator iter = set.reactions(); iter.hasNext();) {
 
142
            IReaction reaction = (IReaction)iter.next();
 
143
            IAtomContainer container = ReactionManipulator.getRelevantAtomContainer(reaction, bond);
 
144
            if (container != null) { // a match!
 
145
                return container;
 
146
            }
 
147
        }
 
148
        return null;
 
149
    }
 
150
    
 
151
    public static void setAtomProperties(IReactionSet set, Object propKey, Object propVal) {
 
152
        for (java.util.Iterator iter = set.reactions(); iter.hasNext();) {
 
153
            IReaction reaction = (IReaction)iter.next();
 
154
            ReactionManipulator.setAtomProperties(reaction, propKey, propVal);
 
155
        }
 
156
    }
 
157
    
 
158
    public static List getAllChemObjects(IReactionSet set) {
 
159
        ArrayList list = new ArrayList();
 
160
        list.add(set);
 
161
        for (java.util.Iterator iter = set.reactions(); iter.hasNext();) {
 
162
            IReaction reaction = (IReaction)iter.next();
 
163
            list.addAll(ReactionManipulator.getAllChemObjects(reaction));
 
164
        }
 
165
        return list;
 
166
    }
 
167
    
 
168
}