~ubuntu-branches/ubuntu/trusty/cdk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/applications/jchempaint/action/PerceiveAtomTypesAction.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
/*  $Revision: 7032 $ $Author: kaihartmann $ $Date: 2006-09-22 17:26:48 +0200 (Fri, 22 Sep 2006) $
 
2
 *  
 
3
 *  Copyright (C) 2006-2007  Egon Willighagen <ewilligh@uni-koeln.de>
 
4
 *
 
5
 *  Contact: cdk-devel@lists.sf.net
 
6
 *
 
7
 *  This program is free software; you can redistribute it and/or
 
8
 *  modify it under the terms of the GNU Lesser General Public License
 
9
 *  as published by the Free Software Foundation; either version 2.1
 
10
 *  of the License, or (at your option) any later version.
 
11
 *  All we ask is that proper credit is given for our work, which includes
 
12
 *  - but is not limited to - adding the above copyright notice to the beginning
 
13
 *  of your source code files, and to any copyright notice that you may distribute
 
14
 *  with programs based on this work.
 
15
 *
 
16
 *  This program is distributed in the hope that it will be useful,
 
17
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
 *  GNU Lesser General Public License for more details.
 
20
 *
 
21
 *  You should have received a copy of the GNU Lesser General Public License
 
22
 *  along with this program; if not, write to the Free Software
 
23
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
24
 */
 
25
package org.openscience.cdk.applications.jchempaint.action;
 
26
 
 
27
import java.awt.event.ActionEvent;
 
28
import java.util.Iterator;
 
29
 
 
30
import org.openscience.cdk.applications.jchempaint.JChemPaintModel;
 
31
import org.openscience.cdk.applications.jchempaint.dialogs.ValidateFrame;
 
32
import org.openscience.cdk.atomtype.IAtomTypeMatcher;
 
33
import org.openscience.cdk.atomtype.MM2AtomTypeMatcher;
 
34
import org.openscience.cdk.atomtype.MMFF94AtomTypeMatcher;
 
35
import org.openscience.cdk.exception.CDKException;
 
36
import org.openscience.cdk.interfaces.IAtom;
 
37
import org.openscience.cdk.interfaces.IAtomContainer;
 
38
import org.openscience.cdk.interfaces.IChemModel;
 
39
import org.openscience.cdk.tools.manipulator.ChemModelManipulator;
 
40
 
 
41
/**
 
42
 * An action that triggers atom type perception by the CDK.
 
43
 * 
 
44
 * @cdk.module jchempaint
 
45
 * @author     E.L. Willighagen <ewilligh@uni-koeln.de>
 
46
 */
 
47
public class PerceiveAtomTypesAction extends JCPAction
 
48
{
 
49
 
 
50
    private static final long serialVersionUID = -3776589605934024224L;
 
51
    
 
52
    ValidateFrame frame = null;
 
53
 
 
54
        public void actionPerformed(ActionEvent event) {
 
55
                logger.debug("detected force field type list: ", type);
 
56
                IAtomTypeMatcher matcher = null;
 
57
                if ("mm2".equals(type)) {
 
58
                        matcher = new MM2AtomTypeMatcher();
 
59
                } else if ("mmff94".equals(type)) {
 
60
                        matcher = new MMFF94AtomTypeMatcher();
 
61
                }
 
62
                if (matcher == null) {
 
63
                        logger.warn("Not a known atom type list: " + type);
 
64
                        return;
 
65
                }
 
66
                
 
67
                JChemPaintModel jcpmodel = jcpPanel.getJChemPaintModel();
 
68
                IChemModel model = jcpmodel.getChemModel();
 
69
                
 
70
                Iterator containers = ChemModelManipulator.getAllAtomContainers(model).iterator();
 
71
                while (containers.hasNext()) {
 
72
                        IAtomContainer container = (IAtomContainer)containers.next();
 
73
                        Iterator atoms = container.atoms();
 
74
                        while (atoms.hasNext()) {
 
75
                                IAtom atom = (IAtom)atoms.next();
 
76
                                try {
 
77
                                        atom.setAtomTypeName(matcher.findMatchingAtomType(container, atom).getAtomTypeName());
 
78
                                } catch (CDKException e) {
 
79
                                        logger.error("Could not find atom type name for atom!", e);
 
80
                                        logger.debug(e);
 
81
                                }
 
82
                        }
 
83
                }
 
84
        }
 
85
 
 
86
}
 
87