Skip to content

Improve altLoc parsing #76

Closed
Closed

Description

@andreasprlic

Looking at PDB ID 1AAC, residue nr 27, it turns out that some of the side-chain atoms are only listed in the alternate locations for the group, but not in the "main" group. The main group should be as complete as possible and contain a reference to the first occurrence of any atom.

Activity

  1. josemduarte commented on Feb 28, 2014

    @josemduarte
    Contributor

    I have just come across this issue (which by the way is causing also issue #48 ) and it seems to be something potentially affecting any piece of code that uses coordinates. By default getAtomArray methods in StructureTools are getting atoms from the "main" group only. In structures with alt locations that gives an incomplete structure, even at the backbone level, e.g. 3piu contains 54 CA (out of ~ 400) in alt locations.

    I agree with Andreas: the solution to this should be making sure that the parsers assign all first occurrences of atoms to the "main" or let's call it better "default" group. If someone wants to do something fancy with alt locs then it should still be possible to use getAltLoc methods to choose specific locations.

  2. andreasprlic commented on Feb 28, 2014

    @andreasprlic
    MemberAuthor

    Hi Jose,

    I just wrote the following unit test and it seems that 3PIU is getting represented correctly. This is because Group.getAtom(name) actually checks altLocs. Need to go back and take a look at 1AAC what is going on there and come up with a unit test that can demonstrate the issue.

    try {

            Structure structure = StructureIO.getStructure("3PIU");
    
            assertNotNull(structure);
    
            Atom[] ca = StructureTools.getAtomCAArray(structure);
    
            System.out.println(structure.getPdbId() + " has # CA atoms: " + ca.length);
    
            List<Atom> caList = new ArrayList<Atom>();
            for ( Chain c: structure.getChains()){
                for (Group g: c.getAtomGroups()){
                    List<Atom> atoms = g.getAtoms();
                    boolean caInMain = false;
                    for (Atom a: atoms){
    
                        if ( a.getFullName().equals(StructureTools.caAtomName)) {
                            caList.add(a);
                            caInMain = true;
                            break;
                        }                       
                    }
                    if (! caInMain && g.hasAtom(StructureTools.caAtomName)){
                        // g.hasAtom checks altLocs
                        fail("CA is not in main group, but in altLoc");
                    }                   
                }
            }
    
            assertTrue(ca.length == caList.size());
    
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            fail(e.getMessage());
        }
    
  3. andreasprlic commented on Feb 28, 2014

    @andreasprlic
    MemberAuthor

    I think I fixed this with these commits.

  4. josemduarte commented on Feb 28, 2014

    @josemduarte
    Contributor

    Awesome! I've done a very quick test with the ASA calculation code I am writing and it seems it works well with this fix. I'll have to check a few more things, but it seems that this should do it. Thanks!

  5. andreasprlic commented on Feb 28, 2014

    @andreasprlic
    MemberAuthor

    I also added a small improvement that should result in slightly lower memory consumption: all collections within Groups are now trimmed to size.

  6. sbliven commented on Mar 3, 2014

    @sbliven
    Member

    Does this work with AtomIterator as well?

    Group g;
    Iterator<Atom> it = g.iterator();
    while(it.hasNext()) {
        Atom a = it.next();
        ...
    }
    

    (Also, we should make Group extend Iterable<Atom> so we can use for(Atom a: group))

  7. sbliven commented on Mar 3, 2014

    @sbliven
    Member

    I'm a little confused by the data model for altlocs. It seems like it is intended that the main group contain all atoms with a altloc column of ' ', the first altloc contain only atoms with 'A' in that column, the second 'B', etc. (Although @josemduarte found that this is not the case currently for 3PUI). Thus, to get all atoms for a particular conformation requires joining the atoms of the parent group with those of one altloc group.

    To me this seems like the wrong model. A 'Group' should represent all atoms of a particular residue. Thus, alternative conformation Groups should share common Atom objects between them (with atom.parent() pointing at the 'A' Group) plus include their unique Atoms.

  8. josemduarte commented on Mar 3, 2014

    @josemduarte
    Contributor

    So from my tests all seems fine with default group alt locs.

    However we've found a further problem with other alt loc groups. It looks like when you get alt loc group with Group.getAltLocs() the groups are not returning what I would expect, e.g. for 3piu residue 43, there's 2 groups returned:

    A    43 MET
        N       219
        CA  A   220
        CB  A   224
        CG  A   226
        SD  A   228
        CE  A   230
    A    43 MET
        N       219
        CA  A   220
        CA  B   221
        CB  B   225
        CG  B   227
        SD  B   229
        CE  B   231
    

    The first one includes an alt-loc=' ' atom (N) and the second one includes both an alt_loc=' ' (N) plus an alt_loc='A' (CA).

    In fact if I modify the TestAltLocs as following, the test fails:

    diff --git a/biojava3-structure/src/test/java/org/biojava/bio/structure/TestAltLocs.java b/biojava3-structure/src/test/java/org/biojava/bio/structure/TestAltLocs.java
    index 3cdcacd..7f3e790 100644
    --- a/biojava3-structure/src/test/java/org/biojava/bio/structure/TestAltLocs.java
    +++ b/biojava3-structure/src/test/java/org/biojava/bio/structure/TestAltLocs.java
    @@ -246,6 +246,9 @@ public class TestAltLocs extends TestCase {
                            List<Atom> caList = new ArrayList<Atom>();
                            for ( Chain c: structure.getChains()){
                                    for (Group g: c.getAtomGroups()){
    +                                       
    +                                       ensureAllAtomsSameInsCode(g);
    +                                       
                                            List<Atom> atoms = g.getAtoms();
                                            boolean caInMain = false;
                                            for (Atom a: atoms){
    
    
  9. andreasprlic commented on Mar 7, 2014

    @andreasprlic
    MemberAuthor

    I think this is a wrong test. Based on the new assumption the first group can have mixed insertion codes in different atoms, because we want to have all atoms in the group.

  10. josemduarte commented on Mar 7, 2014

    @josemduarte
    Contributor

    You are absolutely right... that didn't really make sense, sorry about that. So of course what I was trying to do was this:

    --- a/biojava3-structure/src/test/java/org/biojava/bio/structure/TestAltLocs.java
    +++ b/biojava3-structure/src/test/java/org/biojava/bio/structure/TestAltLocs.java
    @@ -246,6 +246,11 @@ public class TestAltLocs extends TestCase {
                            List<Atom> caList = new ArrayList<Atom>();
                            for ( Chain c: structure.getChains()){
                                    for (Group g: c.getAtomGroups()){
    +                                       
    +                                       for (Group altLocGroup:g.getAltLocs()) {
    +                                               ensureAllAtomsSameInsCode(altLocGroup);
    +                                       }
    +                                       
                                            List<Atom> atoms = g.getAtoms();
                                            boolean caInMain = false;
                                            for (Atom a: atoms){
    
    

    Which indeed passes without problems. So it looks like the issue can remain closed. I'll add the above in my next pull request.

  11. sbliven commented on Mar 8, 2014

    @sbliven
    Member

    That might be the wrong test there, but the comment before is with mixed codes in altlocs, which should be disallowed.

    If the tests pass, are you getting different output for 3piu residue 43 altlocs?

  12. josemduarte commented on Mar 10, 2014

    @josemduarte
    Contributor

    The output in my comment above was produced with the following code. I've just re-run it now and I can't reproduce that anymore after Andreas' fix. So everything is fine after all.

            for (Chain chain:structure.getChains()) {
                for (Group alt:chain.getAtomGroups()) {
                    List<Group> alllocs = alt.getAltLocs();
                    alllocs.add(alt);
                    for(Group res: alllocs) {
                        if (res.getType().equals(GroupType.HETATM)) continue;
                        System.out.printf("%1s\t%3s\t%s\n",chain.getChainID(),res.getResidueNumber().toString(),res.getPDBName());
                        for (Atom atom:res.getAtoms()) {
                            if (atom.getElement()!=Element.H) {
                                System.out.println("    "+atom.getName()+"\t"+atom.getAltLoc()+ "\t"+atom.getPDBserial());
                            }
    
                        }
                    }
                }
            }
    
    
  13. sbliven commented on Mar 10, 2014

    @sbliven
    Member

    Good.

  14. josemduarte commented on Mar 18, 2014

    @josemduarte
    Contributor

    Alright so after all there is another issue with this. The PDB parsing was working properly but not the mmCIF parsing. I've added a test for that in TestAltLocs in this new branch: https://github.com/biojava/biojava/tree/testsissue

  15. added a commit that references this issue on Mar 18, 2014
  16. added a commit that references this issue on Jul 3, 2020
    af27102
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovement of existing code or method

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions