Skip to content

Commit e96ec83

Browse files
committed
Remove introduced Point_Type and replace with a map, add test on 1CRN.
1 parent 05dd6e1 commit e96ec83

File tree

3 files changed

+81
-68
lines changed

3 files changed

+81
-68
lines changed

descriptor/qsarmolecular/src/main/java/org/openscience/cdk/geometry/surface/NumericalSurface.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030

3131
import javax.vecmath.Point3d;
3232
import java.util.ArrayList;
33+
import java.util.Collections;
34+
import java.util.HashMap;
3335
import java.util.List;
36+
import java.util.Map;
3437

3538
/**
3639
* A class representing the solvent accessible surface area surface of a molecule.
@@ -119,8 +122,8 @@ private void init() {
119122
for (IAtom atom : atoms) {
120123
if (atom.getPoint3d() == null)
121124
throw new IllegalArgumentException("One or more atoms had no 3D coordinate set");
122-
}
123-
125+
}
126+
124127
// get r_f and geometric center
125128
Point3d cp = new Point3d(0, 0, 0);
126129
double maxRadius = 0;
@@ -165,7 +168,7 @@ private void init() {
165168
logger.info("Obtained points, areas and volumes");
166169

167170
}
168-
171+
169172
/**
170173
* Get an array of all the points on the molecular surface.
171174
*
@@ -187,24 +190,20 @@ public Point3d[] getAllSurfacePoints() {
187190
}
188191
return (ret);
189192
}
190-
191-
public ArrayList<Point_Type> getAllPointswithAtomType() {
192-
int npt = 0;
193-
for (List<Point3d> surfPoint : this.surfPoints)
194-
npt += surfPoint.size();
195-
ArrayList<Point_Type> point_types = new ArrayList<Point_Type>(npt);
196-
int j = 0;
193+
194+
/**
195+
* Get the map from atom to surface points. If an atom does not appear in
196+
* the map it is buried. Atoms may share surface points with other atoms.
197+
*
198+
* @return surface atoms and associated points on the surface
199+
*/
200+
public Map<IAtom, List<Point3d>> getAtomSurfaceMap() {
201+
Map<IAtom,List<Point3d>> map = new HashMap<>();
197202
for (int i = 0; i < this.surfPoints.length; i++) {
198-
List<Point3d> arl = this.surfPoints[i];
199-
for (Point3d p : arl) {
200-
Point_Type point_type = new Point_Type();
201-
point_type.setAtom(this.atoms[i].getAtomicNumber());
202-
point_type.setCoord(p);
203-
point_types.add(point_type);
204-
j++;
205-
}
203+
if (!this.surfPoints[i].isEmpty())
204+
map.put(this.atoms[i], Collections.unmodifiableList(this.surfPoints[i]));
206205
}
207-
return (point_types);
206+
return map;
208207
}
209208

210209
/**

descriptor/qsarmolecular/src/main/java/org/openscience/cdk/geometry/surface/Point_Type.java

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (C) 2019 The Chemistry Development Kit (CDK) project
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 USA
22+
*/
23+
24+
package org.openscience.cdk.geometry.surface;
25+
26+
import org.hamcrest.CoreMatchers;
27+
import org.junit.Test;
28+
import org.openscience.cdk.interfaces.IAtom;
29+
import org.openscience.cdk.interfaces.IAtomContainer;
30+
import org.openscience.cdk.interfaces.IChemFile;
31+
import org.openscience.cdk.interfaces.IChemObjectBuilder;
32+
import org.openscience.cdk.io.PDBReader;
33+
import org.openscience.cdk.silent.SilentChemObjectBuilder;
34+
import org.openscience.cdk.tools.manipulator.ChemFileManipulator;
35+
36+
import javax.vecmath.Point3d;
37+
import java.io.InputStream;
38+
import java.util.HashSet;
39+
import java.util.List;
40+
import java.util.Map;
41+
import java.util.Set;
42+
43+
import static org.junit.Assert.assertThat;
44+
45+
public class NumericalSurfaceTest {
46+
47+
@Test
48+
public void testCranbinSurface() throws Exception {
49+
IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance();
50+
IChemFile chemFile;
51+
String path = "/data/pdb/1crn.pdb";
52+
try (InputStream in = getClass().getResourceAsStream(path);
53+
PDBReader pdbr = new PDBReader(in)) {
54+
chemFile = pdbr.read(bldr.newInstance(IChemFile.class));
55+
}
56+
IAtomContainer mol = ChemFileManipulator.getAllAtomContainers(chemFile).get(0);
57+
NumericalSurface surface = new NumericalSurface(mol);
58+
Map<IAtom, List<Point3d>> map = surface.getAtomSurfaceMap();
59+
assertThat(map.size(), CoreMatchers.is(222));
60+
assertThat(mol.getAtomCount(), CoreMatchers.is(327));
61+
}
62+
63+
}

0 commit comments

Comments
 (0)