Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* BioJava development code
*
* This code may be freely distributed and modified under the
* terms of the GNU Lesser General Public Licence. This should
* be distributed with the code. If you do not have a copy,
* see:
*
* http://www.gnu.org/copyleft/lesser.html
*
* Copyright for this code is held jointly by the individual
* authors. These should be listed in @author doc comments.
*
* For more information on the BioJava project and its aims,
* or to join the biojava-l mailing list, visit the home page
* at:
*
* http://www.biojava.org/
*
*/
package org.biojava.nbio.structure.test.symmetry;

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

import java.io.IOException;

import org.biojava.nbio.structure.Atom;
import org.biojava.nbio.structure.Chain;
import org.biojava.nbio.structure.Structure;
import org.biojava.nbio.structure.StructureException;
import org.biojava.nbio.structure.StructureIO;
import org.biojava.nbio.structure.StructureTools;
import org.biojava.nbio.structure.symmetry.utils.SymmetryTools;
import org.junit.Test;

/**
* Tests for {@link SymmetryTools#getRepresentativeAtoms(Structure)}: only
* biological assemblies expanded as models should have their models joined.
* See https://github.com/biojava/biojava/issues/808
*/
public class TestSymmetryToolsRepresentativeAtoms {

private static int countFirstModel(Structure s) {
int n = 0;
for (Chain c : s.getModel(0)) {
n += StructureTools.getRepresentativeAtomArray(c).length;
}
return n;
}

private static int countAllModels(Structure s) {
int n = 0;
for (int m = 0; m < s.nrModels(); m++) {
for (Chain c : s.getModel(m)) {
n += StructureTools.getRepresentativeAtomArray(c).length;
}
}
return n;
}

/**
* 4TZ5 is an X-ray ensemble refinement with multiple models. The models are
* alternative conformations, not symmetry copies, so only the first one
* should be used.
*/
@Test
public void testMultiModelXrayUsesFirstModel() throws IOException, StructureException {
Structure s = StructureIO.getStructure("4TZ5");
assertFalse(s.isNmr());
assertFalse(s.isBiologicalAssembly());
assertTrue("4TZ5 should have multiple models", s.nrModels() > 1);

Atom[] atoms = SymmetryTools.getRepresentativeAtoms(s);
assertEquals(countFirstModel(s), atoms.length);
}

/**
* A biological assembly expanded as models (multiModel=true) has its
* symmetry copies in separate models, so all models should be joined.
*/
@Test
public void testMultiModelBioAssemblyJoinsModels() throws IOException, StructureException {
// 1HHO bioassembly 1 is a hemoglobin tetramer built from a dimer in the AU
Structure s = StructureIO.getBiologicalAssembly("1hho", 1, true);
assertTrue(s.isBiologicalAssembly());
assertEquals(2, s.nrModels());

Atom[] atoms = SymmetryTools.getRepresentativeAtoms(s);
assertEquals(countAllModels(s), atoms.length);
assertTrue(atoms.length > countFirstModel(s));
}

/**
* A biological assembly expanded as chains (the default) has a single model.
*/
@Test
public void testFlattenedBioAssembly() throws IOException, StructureException {
Structure s = StructureIO.getBiologicalAssembly("1hho", 1, false);
assertEquals(1, s.nrModels());

Atom[] atoms = SymmetryTools.getRepresentativeAtoms(s);
assertEquals(countFirstModel(s), atoms.length);
}

/**
* NMR entries use the first model only.
*/
@Test
public void testNmrUsesFirstModel() throws IOException, StructureException {
Structure s = StructureIO.getStructure("1B4C");
assertTrue(s.isNmr());
assertTrue(s.nrModels() > 1);

Atom[] atoms = SymmetryTools.getRepresentativeAtoms(s);
assertEquals(countFirstModel(s), atoms.length);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -851,30 +851,32 @@ public static void updateSymmetryScores(MultipleAlignment symm)
}

/**
* Returns the representative Atom Array of the first model, if the
* structure is NMR, or the Array for each model, if it is a biological
* assembly with multiple models.
* Returns the representative Atom Array of the first model, unless the
* structure is a biological assembly expanded as models (see
* {@link org.biojava.nbio.structure.quaternary.BiologicalAssemblyBuilder#rebuildQuaternaryStructure(Structure, List, boolean, boolean)}
* with multiModel=true), in which case the representative atoms of all
* models are joined.
* <p>
* Other multi-model structures (NMR ensembles, X-ray ensemble refinements)
* hold alternative conformations in their models, so only the first model
* is used.
*
* @param structure
* @return representative Atom[]
*/
public static Atom[] getRepresentativeAtoms(Structure structure) {

if (structure.isNmr())
if (!structure.isBiologicalAssembly() || structure.nrModels() == 1)
return StructureTools.getRepresentativeAtomArray(structure);

else {

// Get Atoms of all models
List<Atom> atomList = new ArrayList<>();
for (int m = 0; m < structure.nrModels(); m++) {
for (Chain c : structure.getModel(m))
atomList.addAll(Arrays.asList(StructureTools
.getRepresentativeAtomArray(c)));
}
return atomList.toArray(new Atom[0]);
// Biological assembly expanded as models: get Atoms of all models
List<Atom> atomList = new ArrayList<>();
for (int m = 0; m < structure.nrModels(); m++) {
for (Chain c : structure.getModel(m))
atomList.addAll(Arrays.asList(StructureTools
.getRepresentativeAtomArray(c)));
}

return atomList.toArray(new Atom[0]);
}

/**
Expand Down
Loading