public void loadStructureFromCache() {
    String pdbId = "4hhb";
    String chainName = "4hhb.A";
    String entityName = "4hhb:0";

    // we can set a flag if the file should be cached in memory
    // this will enhance IO massively if the same files have to be accessed over and over again.
    // since this is a soft cache, no danger of memory leak
    // this is actually not necessary to provide, since the default is "true" if the AtomCache is
    // being used.
    System.setProperty(InputStreamProvider.CACHE_PROPERTY, "true");

    AtomCache cache = new AtomCache();

    try {
      System.out.println("======================");
      Structure s = cache.getStructure(pdbId);

      System.out.println("Full Structure:" + s);

      Atom[] ca = cache.getAtoms(chainName);
      System.out.println("got " + ca.length + " CA atoms");

      Structure firstEntity = cache.getStructure(entityName);
      System.out.println("First entity: " + firstEntity);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  private static void demoAtomCache() {
    AtomCache cache = new AtomCache();

    FileParsingParameters params = cache.getFileParsingParams();

    params.setLoadChemCompInfo(false);
    params.setAlignSeqRes(true);
    params.setHeaderOnly(false);
    params.setParseCAOnly(false);
    params.setParseSecStruc(false);

    String[] pdbIDs = new String[] {"4hhb", "1cdg", "5pti", "1gav", "WRONGID"};

    for (String pdbID : pdbIDs) {

      try {
        Structure s = cache.getStructure(pdbID);
        if (s == null) {
          System.out.println("could not find structure " + pdbID);
          continue;
        }
        // do something with the structure
        System.out.println(s);

      } catch (Exception e) {
        // something crazy happened...
        System.err.println("Can't load structure " + pdbID + " reason: " + e.getMessage());
        e.printStackTrace();
      }
    }
  }
Exemple #3
0
  public void testFetchObsolete() throws IOException, StructureException {

    cache.setUseMmCif(false); // TODO Remove after implementing obsolete mmcif fetching
    cache.setAutoFetch(true);
    cache.setFetchCurrent(false);
    cache.setFetchFileEvenIfObsolete(true);

    Structure s;

    // OBSOLETE PDB; should throw an exception
    s = cache.getStructure("1CMW");
    assertEquals("Failed to get OBSOLETE file 1CMW.", "1CMW", s.getPDBCode());

    s = cache.getStructure("1HHB");
    assertEquals("Failed to get OBSOLETE file 1HHB.", "1HHB", s.getPDBCode());
    System.err.println(
        "Please ignore the previous four errors. They are expected for this ancient PDB.");
  }
Exemple #4
0
  public void testFetchCurrent() throws IOException, StructureException {

    cache.setUseMmCif(false); // TODO Remove after implementing obsolete mmcif fetching
    cache.setAutoFetch(true);
    cache.setFetchCurrent(true);
    cache.setFetchFileEvenIfObsolete(false);

    Structure s;
    try {
      // OBSOLETE PDB; should throw an exception
      s = cache.getStructure("1CMW");
      fail("1CMW has no current structure. Should have thrown an error");
    } catch (IOException e) {
      // expected
      System.err.println("Please ignore previous exceptions. They are expected.");
    } catch (StructureException e) {
      // expected
      System.err.println("Please ignore previous exceptions. They are expected.");
    }

    s = cache.getStructure("1HHB");
    assertEquals("Failed to get the current ID for 1HHB.", "4HHB", s.getPDBCode());
  }
  public static void main(String[] args) {

    try {
      FileParsingParameters params = new FileParsingParameters();
      params.setParseSecStruc(true);

      AtomCache cache = new AtomCache();
      cache.setFileParsingParams(params);

      Structure s = cache.getStructure("4hhb");

      for (Chain c : s.getChains()) {
        for (Group g : c.getAtomGroups()) {

          if (g instanceof AminoAcid) {

            AminoAcid aa = (AminoAcid) g;

            Map<String, String> sec = aa.getSecStruc();

            System.out.println(
                c.getChainID()
                    + " "
                    + g.getResidueNumber()
                    + " "
                    + g.getPDBName()
                    + " "
                    + " "
                    + sec);
          }
        }
      }

    } catch (Exception e) {

      e.printStackTrace();
    }
  }
Exemple #6
0
  public void testAtomCacheNameParsing() throws IOException, StructureException {

    String name1 = "4hhb";
    Structure s = cache.getStructure(name1);
    assertNotNull(s);
    assertTrue(s.getChains().size() == 4);

    String name2 = "4hhb.C";
    String chainId2 = "C";
    s = cache.getStructure(name2);

    assertTrue(s.getChains().size() == 1);
    Chain c = s.getChainByPDB(chainId2);
    assertEquals(c.getChainID(), chainId2);

    String name3 = "4hhb:1";
    String chainId3 = "B";
    s = cache.getStructure(name3);
    assertNotNull(s);
    assertTrue(s.getChains().size() == 1);

    c = s.getChainByPDB(chainId3);
    assertEquals(c.getChainID(), chainId3);

    String name4 = "4hhb:A:10-20,B:10-20,C:10-20";
    s = cache.getStructure(name4);
    assertNotNull(s);

    assertEquals(s.getChains().size(), 3);

    c = s.getChainByPDB("B");
    assertEquals(c.getAtomLength(), 11);

    String name5 = "4hhb:(A:10-20,A:30-40)";
    s = cache.getStructure(name5);
    assertNotNull(s);

    assertEquals(s.getChains().size(), 1);
    c = s.getChainByPDB("A");
    assertEquals(c.getAtomLength(), 22);

    // This syntax also works, since the first paren is treated as a separator
    String name6 = "4hhb(A:10-20,A:30-40)";
    s = cache.getStructure(name6);
    assertNotNull(s);

    assertEquals(s.getChains().size(), 1);
    c = s.getChainByPDB("A");
    assertEquals(c.getAtomLength(), 22);

    // Doesn't work, since no ':' in name
    // This behavior is questionable; perhaps it should return 4hhb.C?
    // It's not a very likely/important case, I'm just documenting behavior here.
    String name7 = "4hhb(C)";
    s = cache.getStructure(name7);
    assertNull("Invalid substructure style: " + name7, s);

    // Works since we detect a ':'
    String name8 = "4hhb:(C)";
    s = cache.getStructure(name8);

    assertTrue(s.getChains().size() == 1);
    c = s.getChainByPDB(chainId2);
    assertEquals(c.getChainID(), chainId2);
  }