1
/* $Revision: 7032 $ $Author: kaihartmann $ $Date: 2006-09-22 17:26:48 +0200 (Fri, 22 Sep 2006) $
3
* Copyright (C) 2006-2007 Egon Willighagen <ewilligh@uni-koeln.de>
5
* Contact: cdk-devel@lists.sf.net
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.
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.
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.
25
package org.openscience.cdk.applications.jchempaint.action;
27
import java.awt.event.ActionEvent;
28
import java.util.Iterator;
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;
42
* An action that triggers atom type perception by the CDK.
44
* @cdk.module jchempaint
45
* @author E.L. Willighagen <ewilligh@uni-koeln.de>
47
public class PerceiveAtomTypesAction extends JCPAction
50
private static final long serialVersionUID = -3776589605934024224L;
52
ValidateFrame frame = null;
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();
62
if (matcher == null) {
63
logger.warn("Not a known atom type list: " + type);
67
JChemPaintModel jcpmodel = jcpPanel.getJChemPaintModel();
68
IChemModel model = jcpmodel.getChemModel();
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();
77
atom.setAtomTypeName(matcher.findMatchingAtomType(container, atom).getAtomTypeName());
78
} catch (CDKException e) {
79
logger.error("Could not find atom type name for atom!", e);