Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fixing issue: no bonds between different altloc atoms
  • Loading branch information
josemduarte committed Nov 10, 2019
commit 761799b7e8c727d573fa834a5bb36959a0292b10
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public void setBonds(List<Bond> bonds) {
@Override
public void addBond(Bond bond) {
if (bonds==null) {
bonds = new ArrayList<Bond>(BONDS_INITIAL_CAPACITY);
bonds = new ArrayList<>(BONDS_INITIAL_CAPACITY);
}
bonds.add(bond);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class HetatomImpl implements Group {
* Behaviors for how to balance memory vs. performance.
* @author Andreas Prlic
*/
public static enum PerformanceBehavior {
public enum PerformanceBehavior {

/** use a built-in HashMap for faster access to memory, at the price of more memory consumption */
BETTER_PERFORMANCE_MORE_MEMORY,
Expand All @@ -87,7 +87,7 @@ public static enum PerformanceBehavior {

}

public static PerformanceBehavior performanceBehavior=PerformanceBehavior.LESS_MEMORY_SLOWER_PERFORMANCE;
private static PerformanceBehavior performanceBehavior=PerformanceBehavior.LESS_MEMORY_SLOWER_PERFORMANCE;

private Map<String,Atom> atomNameLookup;

Expand All @@ -105,42 +105,28 @@ public HetatomImpl() {
pdb_name = null ;

residueNumber = null;
atoms = new ArrayList<Atom>();
properties = new HashMap<String,Object>();
atoms = new ArrayList<>();
properties = new HashMap<>();
parent = null;
chemComp = null;
altLocs = null;

if ( performanceBehavior == PerformanceBehavior.BETTER_PERFORMANCE_MORE_MEMORY)
atomNameLookup = new HashMap<String,Atom>();
atomNameLookup = new HashMap<>();
else
atomNameLookup = null;
}


/**
* returns true or false, depending if this group has 3D coordinates or not.
* @return true if Group has 3D coordinates
*/
@Override
public boolean has3D() {
return pdb_flag;
}

/** flag if group has 3D data.
*
* @param flag true to set flag that this Group has 3D coordinates
*/
@Override
public void setPDBFlag(boolean flag){
pdb_flag = flag ;
}

/** Set three character name of Group .
*
* @param s a String specifying the PDBName value
* @see #getPDBName
*/
@Override
public void setPDBName(String s) {
// hetatoms can have pdb_name length < 3. e.g. CU (see 1a4a position 1200 )
Expand All @@ -152,12 +138,6 @@ public void setPDBName(String s) {

}

/**
* Returns the PDBName.
*
* @return a String representing the PDBName value
* @see #setPDBName
*/
@Override
public String getPDBName() { return pdb_name;}

Expand Down Expand Up @@ -187,12 +167,8 @@ public void addAtom(Atom atom){
logger.warn("An atom with name " + atom.getName() + " " + altLocStr + " is already present in group: " + this.toString() + ". The atom with serial " + atom.getPDBserial() + " will be ignored in look-ups.");
}
}
};

}

/** remove all atoms
*
*/
@Override
public void clearAtoms() {
atoms.clear();
Expand Down Expand Up @@ -245,8 +221,7 @@ public Atom getAtom(String name) {
if ( atomNameLookup != null)
return atomNameLookup.get(name);
else {
/** This is the performance penalty we pay for NOT using the atomnameLookup in PerformanceBehaviour.LESS_MEMORY_SLOWER_PERFORMANCE
*/
// This is the performance penalty we pay for NOT using the atomnameLookup in PerformanceBehaviour.LESS_MEMORY_SLOWER_PERFORMANCE
for (Atom a : atoms) {
if (a.getName().equals(name)) {
return a;
Expand Down Expand Up @@ -588,7 +563,7 @@ public boolean hasAltLoc() {
@Override
public List<Group> getAltLocs() {
if ( altLocs == null)
return new ArrayList<Group>();
return new ArrayList<>();
return altLocs;
}

Expand Down Expand Up @@ -629,7 +604,7 @@ public Group getAltLocGroup(Character altLoc) {
@Override
public void addAltLoc(Group group) {
if ( altLocs == null) {
altLocs = new ArrayList<Group>();
altLocs = new ArrayList<>();
}
altLocs.add(group);

Expand Down Expand Up @@ -663,10 +638,10 @@ public void trimToSize(){
}

// now let's fit the hashmaps to size
properties = new HashMap<String, Object>(properties);
properties = new HashMap<>(properties);

if ( atomNameLookup != null)
atomNameLookup = new HashMap<String,Atom>(atomNameLookup);
atomNameLookup = new HashMap<>(atomNameLookup);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,7 @@ private void formIntraResidueBonds() {
// Now add support for altLocGroup
List<Group> totList = new ArrayList<Group>();
totList.add(mainGroup);
for(Group altLoc: mainGroup.getAltLocs()){
totList.add(altLoc);
}

totList.addAll(mainGroup.getAltLocs());

// Now iterate through this list
for(Group group : totList){
Expand All @@ -216,15 +213,19 @@ private void formIntraResidueBonds() {
Atom a = getAtom(chemCompBond.getAtom_id_1(), group);
Atom b = getAtom(chemCompBond.getAtom_id_2(), group);
if ( a != null && b != null){

// if they are different altlocs there must be no bond
if (a.getAltLoc() != b.getAltLoc())
continue;

int bondOrder = chemCompBond.getNumericalBondOrder();
logger.debug("Forming bond between atoms {}-{} and {}-{} with bond order {}",
a.getPDBserial(), a.getName(), b.getPDBserial(), b.getName(), bondOrder);
new BondImpl(a, b, bondOrder);
}
else{
// Some of the atoms were missing. That's fine, there's
// nothing to do in this case.
}
// Else: Some of the atoms were missing. That's fine, there's
// nothing to do in this case.

}
}
}
Expand All @@ -235,6 +236,7 @@ private void formIntraResidueBonds() {

private Atom getAtom(String atomId, Group group) {
Atom a = group.getAtom(atomId);

// Check for deuteration
if(a==null && atomId.startsWith("H")) {
a = group.getAtom(atomId.replaceFirst("H", "D"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -754,4 +754,97 @@ public void testMmcifConversionAllAltlocs() throws IOException {

}

/**
* Test that bonds between alt locs link atoms with same altloc codes
* https://github.com/rcsb/mmtf/issues/44
*/
@Test
public void testBondsBetweenAltlocs() throws IOException {
String mmcifData =
"data_test\n" +
"loop_\n" +
"_atom_site.group_PDB \n" +
"_atom_site.id \n" +
"_atom_site.type_symbol \n" +
"_atom_site.label_atom_id \n" +
"_atom_site.label_alt_id \n" +
"_atom_site.label_comp_id \n" +
"_atom_site.label_asym_id \n" +
"_atom_site.label_entity_id \n" +
"_atom_site.label_seq_id \n" +
"_atom_site.pdbx_PDB_ins_code \n" +
"_atom_site.Cartn_x \n" +
"_atom_site.Cartn_y \n" +
"_atom_site.Cartn_z \n" +
"_atom_site.occupancy \n" +
"_atom_site.B_iso_or_equiv \n" +
"_atom_site.pdbx_formal_charge \n" +
"_atom_site.auth_seq_id \n" +
"_atom_site.auth_comp_id \n" +
"_atom_site.auth_asym_id \n" +
"_atom_site.auth_atom_id \n" +
"_atom_site.pdbx_PDB_model_num \n" +
"ATOM 1405 N N A MET A 1 86 ? 10.748 -17.610 -6.975 0.47 16.12 ? 104 MET A N 1 \n" +
"ATOM 1406 N N B MET A 1 86 ? 10.802 -17.694 -6.986 0.53 17.92 ? 104 MET A N 1 \n" +
"ATOM 1407 C CA A MET A 1 86 ? 11.189 -17.392 -5.610 0.47 15.78 ? 104 MET A CA 1 \n" +
"ATOM 1408 C CA B MET A 1 86 ? 11.033 -17.368 -5.587 0.53 18.29 ? 104 MET A CA 1 \n" +
"ATOM 1409 C C A MET A 1 86 ? 10.952 -18.663 -4.810 0.47 15.91 ? 104 MET A C 1 \n" +
"ATOM 1410 C C B MET A 1 86 ? 10.882 -18.643 -4.767 0.53 17.40 ? 104 MET A C 1 \n" +
"ATOM 1411 O O A MET A 1 86 ? 10.120 -19.504 -5.154 0.47 18.21 ? 104 MET A O 1 \n" +
"ATOM 1412 O O B MET A 1 86 ? 10.018 -19.474 -5.052 0.53 20.02 ? 104 MET A O 1 \n" +
"ATOM 1413 C CB A MET A 1 86 ? 10.477 -16.204 -4.933 0.47 17.14 ? 104 MET A CB 1 \n" +
"ATOM 1414 C CB B MET A 1 86 ? 10.001 -16.336 -5.111 0.53 18.92 ? 104 MET A CB 1 \n" +
"ATOM 1415 C CG A MET A 1 86 ? 9.019 -16.476 -4.619 0.47 20.01 ? 104 MET A CG 1 \n" +
"ATOM 1416 C CG B MET A 1 86 ? 10.030 -16.038 -3.634 0.53 19.12 ? 104 MET A CG 1 \n" +
"ATOM 1417 S SD A MET A 1 86 ? 8.207 -15.088 -3.838 0.47 22.06 ? 104 MET A SD 1 \n" +
"ATOM 1418 S SD B MET A 1 86 ? 8.874 -14.724 -3.205 0.53 20.16 ? 104 MET A SD 1 \n" +
"ATOM 1419 C CE A MET A 1 86 ? 9.151 -14.973 -2.340 0.47 25.15 ? 104 MET A CE 1 \n" +
"ATOM 1420 C CE B MET A 1 86 ? 7.269 -15.536 -3.380 0.53 20.38 ? 104 MET A CE 1 \n" +
"ATOM 1421 H H A MET A 1 86 ? 9.931 -18.207 -7.055 0.47 15.58 ? 104 MET A H 1 \n" +
"ATOM 1422 H H B MET A 1 86 ? 10.144 -18.461 -7.109 0.53 18.91 ? 104 MET A H 1 \n" +
"ATOM 1423 H HA A MET A 1 86 ? 12.256 -17.182 -5.644 0.47 15.14 ? 104 MET A HA 1 \n" +
"ATOM 1424 H HA B MET A 1 86 ? 12.033 -16.953 -5.465 0.53 19.55 ? 104 MET A HA 1 \n" +
"ATOM 1425 H HB2 A MET A 1 86 ? 10.986 -15.920 -4.008 0.47 17.68 ? 104 MET A HB2 1 \n" +
"ATOM 1426 H HB3 A MET A 1 86 ? 10.484 -15.364 -5.622 0.47 17.68 ? 104 MET A HB3 1 \n" +
"ATOM 1427 H HB3 B MET A 1 86 ? 9.001 -16.676 -5.398 0.53 20.49 ? 104 MET A HB3 1 \n" +
"ATOM 1428 H HG2 A MET A 1 86 ? 8.490 -16.704 -5.546 0.47 20.93 ? 104 MET A HG2 1 \n" +
"ATOM 1429 H HG3 A MET A 1 86 ? 8.956 -17.315 -3.927 0.47 20.93 ? 104 MET A HG3 1 \n" +
"ATOM 1430 H HE2 A MET A 1 86 ? 9.861 -14.153 -2.440 0.47 27.31 ? 104 MET A HE2 1 \n" +
"ATOM 1431 H HE2 B MET A 1 86 ? 7.346 -16.554 -2.998 0.53 23.03 ? 104 MET A HE2 1 \n" +
"ATOM 1432 H HE3 B MET A 1 86 ? 6.996 -15.566 -4.437 0.53 23.03 ? 104 MET A HE3 1 ";

SimpleMMcifParser parser = new SimpleMMcifParser();
SimpleMMcifConsumer consumer = new SimpleMMcifConsumer();
parser.addMMcifConsumer(consumer);

FileParsingParameters params = new FileParsingParameters();
params.setCreateAtomBonds(true);
consumer.setFileParsingParameters(params);

BufferedReader buf = new BufferedReader(new StringReader(mmcifData));
parser.parse(buf);
buf.close();

Structure s = consumer.getStructure();
Chain c = s.getPolyChains().get(0);
assertEquals(1, c.getAtomGroups().size());

Group g = c.getAtomGroup(0);

assertEquals(1, g.getAltLocs().size());

for (Atom a : g.getAtoms()) {
for (Bond b : a.getBonds()) {
// if (b.getAtomA().getAltLoc() != b.getAtomB().getAltLoc()) {
// System.out.println(
// b.getAtomA().toString() + ":" + b.getAtomA().getAltLoc() + " --- " +
// b.getAtomB().toString() + ":" + b.getAtomB().getAltLoc());
// }
assertEquals(b.getAtomA().toString() + " --- " + b.getAtomB().toString(),
b.getAtomA().getAltLoc(), b.getAtomB().getAltLoc());
}
}

}

}