Skip to content

Commit a743727

Browse files
authored
Merge pull request biojava#632 from josemduarte/master
Fix for issue 631
2 parents f73c9e6 + 80a3eaa commit a743727

4 files changed

Lines changed: 85 additions & 15 deletions

File tree

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/StructureToolsTest.java

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,28 @@
2222
*/
2323
package org.biojava.nbio.structure.test;
2424

25-
import junit.framework.TestCase;
26-
2725
import org.biojava.nbio.structure.*;
2826
import org.biojava.nbio.structure.align.util.AtomCache;
2927
import org.biojava.nbio.structure.io.FileParsingParameters;
3028
import org.biojava.nbio.structure.io.PDBFileParser;
3129
import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory;
3230
import org.biojava.nbio.structure.io.mmcif.ChemCompProvider;
3331
import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider;
32+
import org.junit.Before;
33+
import org.junit.Test;
3434

3535
import java.io.IOException;
3636
import java.io.InputStream;
3737

3838
import static org.junit.Assume.assumeNoException;
39+
import static org.junit.Assert.*;
3940

40-
public class StructureToolsTest extends TestCase {
41+
public class StructureToolsTest {
4142

4243
Structure structure, structure2, structure3, structure4;
4344

44-
@Override
45-
protected void setUp() throws IOException
45+
@Before
46+
public void setUp() throws IOException
4647
{
4748
InputStream inStream = this.getClass().getResourceAsStream("/5pti.pdb");
4849
assertNotNull(inStream);
@@ -86,12 +87,13 @@ protected void setUp() throws IOException
8687
inStream.close();
8788
}
8889

89-
90+
@Test
9091
public void testGetCAAtoms(){
9192
Atom[] cas = StructureTools.getRepresentativeAtomArray(structure);
9293
assertEquals("did not find the expected number of Atoms (58), but got " + cas.length,58,cas.length);
9394
}
9495

96+
@Test
9597
public void testGetAtomsConsistency() throws IOException, StructureException{
9698

9799
//Save the existing ChemCompProvider
@@ -121,11 +123,13 @@ public void testGetAtomsConsistency() throws IOException, StructureException{
121123
ChemCompGroupFactory.setChemCompProvider(provider);
122124
}
123125

126+
@Test
124127
public void testGetNrAtoms(){
125128
int length = StructureTools.getNrAtoms(structure);
126129
assertEquals("did not find the expected number of Atoms (1087), but got " + length,1087,length);
127130
}
128131

132+
@Test
129133
@SuppressWarnings("deprecation")
130134
public void testGetSubRanges() throws StructureException {
131135
String range;
@@ -263,6 +267,7 @@ public void testGetSubRanges() throws StructureException {
263267
} catch(IllegalArgumentException ex) {} //expected
264268
}
265269

270+
@Test
266271
public void testRevisedConvention() throws IOException, StructureException{
267272

268273
AtomCache cache = new AtomCache();
@@ -348,6 +353,7 @@ public void testRevisedConvention() throws IOException, StructureException{
348353
* Test some subranges that we used to have problems with
349354
* @throws StructureException
350355
*/
356+
@Test
351357
@SuppressWarnings("deprecation")
352358
public void testGetSubRangesExtended() throws StructureException {
353359
String range;
@@ -444,6 +450,7 @@ public void testGetSubRangesExtended() throws StructureException {
444450
* Test insertion codes
445451
* @throws StructureException
446452
*/
453+
@Test
447454
@SuppressWarnings("deprecation")
448455
public void testGetSubRangesInsertionCodes() throws StructureException {
449456
String range;
@@ -501,6 +508,7 @@ public void testGroupsWithinShell() {
501508
//TODO
502509
}
503510

511+
@Test
504512
public void testCAmmCIF() throws StructureException {
505513

506514
//Save the existing ChemCompProvider
@@ -537,5 +545,36 @@ public void testCAmmCIF() throws StructureException {
537545

538546
ChemCompGroupFactory.setChemCompProvider(provider);
539547
}
548+
549+
@Test
550+
public void testGetRepresentativeAtomsProtein() throws StructureException, IOException {
551+
Structure s = StructureIO.getStructure("1smt");
552+
Chain c = s.getChainByIndex(0);
553+
Atom[] atoms = StructureTools.getRepresentativeAtomArray(c);
554+
assertEquals(98,atoms.length);
555+
556+
Chain clonedChain = (Chain)c.clone();
557+
atoms = StructureTools.getRepresentativeAtomArray(clonedChain);
558+
assertEquals(98,atoms.length);
559+
}
540560

561+
/**
562+
* See https://github.com/biojava/biojava/issues/631
563+
* @throws StructureException
564+
* @throws IOException
565+
*/
566+
@Test
567+
public void testGetRepresentativeAtomsDna() throws StructureException, IOException {
568+
569+
Structure s = StructureIO.getStructure("2pvi");
570+
Chain c = s.getPolyChainByPDB("C");
571+
Atom[] atoms = StructureTools.getRepresentativeAtomArray(c); // chain C (1st nucleotide chain)
572+
// actually it should be 13, but at the moment one of the nucleotides is not caught correctly because it's non-standard
573+
assertEquals(12,atoms.length);
574+
575+
Chain clonedChain = (Chain)c.clone();
576+
atoms = StructureTools.getRepresentativeAtomArray(clonedChain); // chain C (1st nucleotide chain)
577+
assertEquals(12,atoms.length);
578+
579+
}
541580
}

biojava-structure/src/main/java/org/biojava/nbio/structure/Calc.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,10 @@ public static final void shift(Group group, Atom a) {
777777
* @return an Atom representing the Centroid of the set of atoms
778778
*/
779779
public static final Atom getCentroid(Atom[] atomSet) {
780+
781+
// if we don't catch this case, the centroid returned is (NaN,NaN,NaN), which can cause lots of problems down the line
782+
if (atomSet.length==0)
783+
throw new IllegalArgumentException("Atom array has length 0, can't calculate centroid!");
780784

781785
double[] coords = new double[3];
782786

biojava-structure/src/main/java/org/biojava/nbio/structure/NucleotideImpl.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,36 @@ public Atom getP() {
9393

9494
}
9595

96-
// no need to implement clone here, it's already in super class
96+
// note we need to implement a clone here, despite there's one in super class already,
97+
// that's due to issue https://github.com/biojava/biojava/issues/631 - JD 2017-01-21
98+
@Override
99+
public Object clone() {
100+
101+
NucleotideImpl n = new NucleotideImpl();
102+
n.setPDBFlag(has3D());
103+
n.setResidueNumber(getResidueNumber());
104+
105+
n.setPDBName(getPDBName());
106+
107+
// copy the atoms
108+
for (Atom atom1 : atoms) {
109+
Atom atom = (Atom) atom1.clone();
110+
n.addAtom(atom);
111+
atom.setGroup(n);
112+
}
113+
114+
// copying the alt loc groups if present, otherwise they stay null
115+
if (getAltLocs()!=null && !getAltLocs().isEmpty()) {
116+
for (Group altLocGroup:this.getAltLocs()) {
117+
Group nAltLocGroup = (Group)altLocGroup.clone();
118+
n.addAltLoc(nAltLocGroup);
119+
}
120+
}
121+
122+
if (chemComp!=null)
123+
n.setChemComp(chemComp);
124+
125+
126+
return n;
127+
}
97128
}

biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -449,20 +449,16 @@ else if (atomCode.equals("CA") || atomCode.equals("CB") ||
449449
else if (atomCode.equals("CG")) return TETRAHEDRAL_CARBON_VDW;
450450

451451
default:
452-
logger.warn("Unexpected carbon atom "+atomCode+" for aminoacid "+aa+", assigning its standard vdw radius");
452+
logger.info("Unexpected carbon atom "+atomCode+" for aminoacid "+aa+", assigning its standard vdw radius");
453453
return Element.C.getVDWRadius();
454454
}
455455
}
456456

457457
// not any of the expected atoms
458458
} else {
459459
// non standard aas, (e.g. MSE, LLP) will always have this problem,
460-
// thus we log at info level for them, at warn for others
461-
if (amino.getChemComp()!=null && amino.getChemComp().isStandard()) {
462-
logger.warn("Unexpected atom "+atomCode+" for aminoacid "+aa+ " ("+amino.getPDBName()+"), assigning its standard vdw radius");
463-
} else {
464-
logger.info("Unexpected atom "+atomCode+" for aminoacid "+aa+ " ("+amino.getPDBName()+"), assigning its standard vdw radius");
465-
}
460+
logger.info("Unexpected atom "+atomCode+" for aminoacid "+aa+ " ("+amino.getPDBName()+"), assigning its standard vdw radius");
461+
466462

467463
return atom.getElement().getVDWRadius();
468464
}
@@ -487,7 +483,7 @@ private static double getRadiusForNucl(NucleotideImpl nuc, Atom atom) {
487483

488484
if (atom.getElement()==Element.O) return OXIGEN_VDW;
489485

490-
logger.warn("Unexpected atom "+atom.getName()+" for nucleotide "+nuc.getPDBName()+", assigning its standard vdw radius");
486+
logger.info("Unexpected atom "+atom.getName()+" for nucleotide "+nuc.getPDBName()+", assigning its standard vdw radius");
491487
return atom.getElement().getVDWRadius();
492488
}
493489

0 commit comments

Comments
 (0)