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();
      }
    }
  }
  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();
    }
  }
Exemple #3
0
  public static void main(String[] args) {

    String file = "/Users/ap3/tmp/4hhb.ce";

    try {
      BufferedReader in = new BufferedReader(new FileReader(file));
      StringBuffer xml = new StringBuffer();
      String str;
      while ((str = in.readLine()) != null) {
        xml.append(str);
      }
      in.close();

      AFPChain[] afps = AFPChainXMLParser.parseMultiXML(xml.toString());
      AFPChain afpChain = afps[0];

      UserConfiguration config = WebStartMain.getWebStartConfig();
      AtomCache cache = new AtomCache(config.getPdbFilePath(), config.isSplit());

      Atom[] ca1 = cache.getAtoms(afpChain.getName1());
      Atom[] ca2 = cache.getAtoms(afpChain.getName2());

      AFPChainXMLParser.rebuildAFPChain(afpChain, ca1, ca2);

      // StructureAlignment algorithm =
      // StructureAlignmentFactory.getAlgorithm(afpChain.getAlgorithmName());
      StructureAlignmentJmol jmol = StructureAlignmentDisplay.display(afpChain, ca1, ca2);

      DisplayAFP.showAlignmentImage(afpChain, ca1, ca2, jmol);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 public static void buildDefault(File censusFile, int[] sunIds) {
   try {
     int maxThreads = Runtime.getRuntime().availableProcessors() - 1;
     ScopDescriptionCensus census = new ScopDescriptionCensus(maxThreads, sunIds);
     census.setOutputWriter(censusFile);
     AtomCache cache = new AtomCache();
     cache.setFetchFileEvenIfObsolete(true);
     census.setCache(cache);
     census.run();
     System.out.println(census);
   } catch (RuntimeException e) {
     logger.fatal(e.getMessage(), e);
   }
 }
  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();
    }
  }
  public static void main(String[] args) {

    // ScopDatabase berkeley = new BerkeleyScopInstallation();

    // ScopFactory.setScopDatabase(berkeley);

    AtomCache cache = new AtomCache();
    // whenever you want to get access to SCOP now request it like this:
    ScopDatabase scop = ScopFactory.getSCOP("1.75");
    ScopFactory.setScopDatabase(scop);

    System.out.println(cache.getPath());
    System.out.println(cache.getCachePath());
    // ... and do something with it

    // eg. you can run all the demos that work for the UK - SCOP (currently at version 1.75)
    // this demo no automatically picks up the Berkeley version (currently 1.75A)
    DemoSCOP scopDemo = new DemoSCOP();

    scopDemo.getCategories();
    scopDemo.printDomainsForPDB();
    scopDemo.traverseHierarchy();
    scopDemo.alignSuperfamily();
  }
Exemple #7
0
  public void setUp() {
    cache = new AtomCache();

    // Delete files which were cached in previous tests
    String cacheDir = cache.getPath();
    String[] uncacheIDs = new String[] {"1cmw", "1hhb", "4hhb"};

    ArrayList<String> extensions = new ArrayList<String>();

    extensions.add(".ent");
    extensions.add(".pdb");
    extensions.add(".ent.gz");
    extensions.add(".pdb.gz");
    extensions.add(".ent.Z");
    extensions.add(".pdb.Z");

    for (String pdbId : uncacheIDs) {
      String middle = pdbId.substring(1, 3).toLowerCase();

      String fpath = cacheDir + lineSplit + middle + lineSplit + pdbId;
      String ppath = cacheDir + lineSplit + middle + lineSplit + "pdb" + pdbId;

      String[] paths = new String[] {fpath, ppath};

      for (int p = 0; p < paths.length; p++) {
        String testpath = paths[p];
        // System.out.println(testpath);
        for (int i = 0; i < extensions.size(); i++) {
          String ex = (String) extensions.get(i);
          // System.out.println("PDBFileReader testing: "+testpath+ex);
          File f = new File(testpath + ex);

          if (f.exists()) {
            System.out.println("Deleting " + testpath + ex);
            assertTrue("Error deleting " + testpath + ex + " during setup.", f.delete());
          }
        }
      }
    }
  }
Exemple #8
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 #9
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());
  }
Exemple #10
0
  private void runSCOPTests() {

    ScopDatabase scop = ScopFactory.getSCOP();

    List<ScopDomain> domains = scop.getDomainsForPDB("4HHB");

    assertTrue(domains.size() == 4);

    // test case sensitivity;
    List<ScopDomain> domains2 = scop.getDomainsForPDB("4hhb");
    assertTrue(domains2.size() == domains.size());

    // System.out.println(domains);

    String scop1m02 =
        "d1m02a_	1m02	A:	k.36.1.1	74353	cl=58788,cf=75796,sf=75797,fa=75798,dm=75799,sp=75800,px=74353";

    List<ScopDomain> domains1m02 = scop.getDomainsForPDB("1m02");
    assertTrue(domains1m02.size() == 1);
    ScopDomain d1 = domains1m02.get(0);

    assertNotNull(d1);

    assertEquals(
        "The toString() methods for ScopDomains don't match the scop display",
        d1.toString(),
        scop1m02);

    List<ScopDomain> domains1cdg = scop.getDomainsForPDB("1CDG");
    assertTrue(domains1cdg.size() == 4);
    ScopDomain d2 = domains1cdg.get(0);
    AtomCache cache = new AtomCache();
    try {
      Structure s = cache.getStructureForDomain(d2);

      // checkRange(s,"A:496-581");
      // now with ligands!
      checkRange(s, "A:496-692");

    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }

    // check a domain with multiple ranges
    List<ScopDomain> domains1xzp = scop.getDomainsForPDB("1xzp");
    assertTrue(domains1xzp.size() == 4);

    try {
      Structure s = cache.getStructureForDomain(domains1xzp.get(0));
      Chain a = s.getChainByPDB("A");

      // now with ligands...
      assertEquals(a.getAtomGroups().size(), 176);

    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }

    // check insertion codes

    List<ScopDomain> domains2bq6 = scop.getDomainsForPDB("2bq6");
    assertTrue(domains2bq6.size() == 2);
    ScopDomain target = scop.getDomainByScopID("d2bq6a1");

    assertNotNull(target);
    try {
      Structure s = cache.getStructureForDomain(target);

      Chain a = s.getChainByPDB("A");
      assertEquals(a.getAtomGroups().size(), 52);
      checkRange(s, "A:1A-49");

    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }
Exemple #11
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);
  }