Skip to content

Commit

Permalink
Add Kazuya's test case (slightly modified to match the expected behav…
Browse files Browse the repository at this point in the history
…iour) and add document that pi-systems with a single double bond are not considered conjugated.
  • Loading branch information
johnmay authored and egonw committed Feb 9, 2022
1 parent 8095d94 commit 1d71596
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
/**
* This class checks if two atoms have pi-contact (this is true when there is
* one and the same conjugated pi-system which contains both atoms, or directly
* linked neighbours of the atoms).
* linked neighbours of the atoms). Only conjugated systems with more than 2
* atoms are considered.
*
* <table border="1"><caption>Parameters for this descriptor:</caption>
* <tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* Copyright (C) 2021 kazuyaujihara
*
* Contact: cdk-devel@lists.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.openscience.cdk.qsar.descriptors.atompair;

import org.junit.Before;
import org.junit.Test;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.qsar.DescriptorValue;
import org.openscience.cdk.qsar.IAtomPairDescriptor;
import org.openscience.cdk.qsar.result.BooleanResult;
import org.openscience.cdk.templates.TestMoleculeFactory;
import org.openscience.cdk.test.qsar.DescriptorTest;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class PiContactDetectionDescriptorTest extends DescriptorTest<IAtomPairDescriptor> {

@Before
public void setUp() throws Exception {
setDescriptor(PiContactDetectionDescriptor.class);
}

@Test
public void testButadiene() {
IAtomContainer mol = TestMoleculeFactory.makeAlkane(4);
mol.getBond(0).setOrder(IBond.Order.DOUBLE);
mol.getBond(2).setOrder(IBond.Order.DOUBLE);
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
assertTrue(checkAtomAtom(mol, i, j));
}

@Test
public void test137() throws CDKException {
IAtomContainer mol = TestMoleculeFactory.makeAlkane(8);
mol.getBond(0).setOrder(IBond.Order.DOUBLE);
mol.getBond(2).setOrder(IBond.Order.DOUBLE);
mol.getBond(6).setOrder(IBond.Order.DOUBLE);
for (int i = 0; i < 5; i++)
for (int j = 0; j < 5; j++)
assertTrue(i + "," + j + " should have pi contact",
checkAtomAtom(mol, i, j));
for (int i = 0; i < 5; i++)
for (int j = 5; j < 8; j++)
assertFalse(i + "," + j + " should NOT have pi contact",
checkAtomAtom(mol, i, j));
// a single double bond is not considered see
assertFalse(checkAtomAtom(mol, 6, 7));
}

private boolean checkAtomAtom(IAtomContainer mol, int i, int j) {
DescriptorValue result = descriptor.calculate(mol.getAtom(i), mol.getAtom(j), mol);
BooleanResult val = (BooleanResult)result.getValue();
return val.booleanValue();
}
}

0 comments on commit 1d71596

Please sign in to comment.