Program: 17058
Project: 17058
Buggy source:
/** 
 * Request a Structure based on a <i>name</i>. <pre> Formal specification for how to specify the <i>name</i>: name     := pdbID | pdbID '.' chainID | pdbID '.' range | scopID range         := '('? range (',' range)? ')'? | chainID | chainID '_' resNum '-' resNum pdbID         := [0-9][a-zA-Z0-9]{3} chainID       := [a-zA-Z0-9] scopID        := 'd' pdbID [a-z_][0-9_] resNum        := [-+]?[0-9]+[A-Za-z]? Example structures: 1TIM     #whole structure 4HHB.C     #single chain 4GCR.A_1-83     #one domain, by residue number 3AA0.A,B     #two chains treated as one structure d2bq6a1     #scop domain </pre> With the additional set of rules: <ul> <li>If only a PDB code is provided, the whole structure will be return including ligands, but the first model only (for NMR). <li>Chain IDs are case sensitive, PDB ids are not. To specify a particular chain write as: 4hhb.A or 4HHB.A </li> <li>To specify a SCOP domain write a scopId e.g. d2bq6a1. Some flexibility can be allowed in SCOP domain names, see   {@link #setStrictSCOP(boolean)}</li> <li>URLs are accepted as well</li> </ul>
 * @param name
 * @return a Structure object, or null if name appears improperly formated (eg too short, etc)
 * @throws IOException The PDB file cannot be cached due to IO errors
 * @throws StructureException The name appeared valid but did not correspond to a structure.Also thrown by some submethods upon errors, eg for poorly formatted subranges.
 */
public Structure getStructure(String name) throws IOException, StructureException {
  if (name.length() < 4)   throw new IllegalArgumentException("String_Node_Str");
  Structure n=null;
  boolean useChainNr=false;
  boolean useDomainInfo=false;
  String range=null;
  int chainNr=-1;
  try {
    String pdbId=null;
    String chainId=null;
    if (name.length() == 4) {
      pdbId=name;
    }
 else     if (name.startsWith("String_Node_Str")) {
      return getStructureFromSCOPDomain(name);
    }
 else     if (name.length() == 6) {
      pdbId=name.substring(0,4);
      if (name.substring(4,5).equals(CHAIN_SPLIT_SYMBOL)) {
        chainId=name.substring(5,6);
      }
 else       if (name.substring(4,5).equals(CHAIN_NR_SYMBOL)) {
        useChainNr=true;
        chainNr=Integer.parseInt(name.substring(5,6));
      }
    }
 else     if ((name.length() > 6) && (name.contains(CHAIN_NR_SYMBOL) || name.contains(UNDERSCORE)) && (!(name.startsWith("String_Node_Str") || name.startsWith("String_Node_Str")))) {
      pdbId=name.substring(0,4);
      useDomainInfo=true;
      range=name.substring(5);
    }
 else     if (name.startsWith("String_Node_Str") || name.startsWith("String_Node_Str")) {
      try {
        URL url=new URL(name);
        return getStructureFromURL(url);
      }
 catch (      Exception e) {
        e.printStackTrace();
        return null;
      }
    }
 else     if (name.startsWith(PDP_DOMAIN_IDENTIFIER)) {
      try {
        return getPDPStructure(name);
      }
 catch (      Exception e) {
        e.printStackTrace();
        return null;
      }
    }
    if (pdbId == null) {
      return null;
    }
    while (checkLoading(pdbId)) {
      try {
        Thread.sleep(100);
      }
 catch (      InterruptedException e) {
        System.err.println(e.getMessage());
      }
    }
    Structure s;
    flagLoading(pdbId);
    try {
      PDBFileReader reader=new PDBFileReader();
      reader.setPath(path);
      reader.setPdbDirectorySplit(isSplit);
      reader.setAutoFetch(autoFetch);
      reader.setFetchFileEvenIfObsolete(fetchFileEvenIfObsolete);
      reader.setFetchCurrent(fetchCurrent);
      reader.setFileParsingParameters(params);
      s=reader.getStructureById(pdbId.toLowerCase());
    }
 catch (    Exception e) {
      flagLoadingFinished(pdbId);
      throw new StructureException(e.getMessage() + "String_Node_Str" + pdbId,e);
    }
    flagLoadingFinished(pdbId);
    if (chainId == null && chainNr < 0 && range == null) {
      n=StructureTools.getReducedStructure(s,-1);
    }
 else {
      if (useChainNr) {
        n=StructureTools.getReducedStructure(s,chainNr);
      }
 else       if (useDomainInfo) {
        n=StructureTools.getSubRanges(s,range);
      }
 else {
        n=StructureTools.getReducedStructure(s,chainId);
      }
    }
  }
 catch (  Exception e) {
    e.printStackTrace();
    throw new StructureException(e.getMessage() + "String_Node_Str" + name,e);
  }
  n.setName(name);
  return n;
}

Fixed version (ground truth):
/** 
 * Request a Structure based on a <i>name</i>. <pre> Formal specification for how to specify the <i>name</i>: name     := pdbID | pdbID '.' chainID | pdbID '.' range | scopID range         := '('? range (',' range)? ')'? | chainID | chainID '_' resNum '-' resNum pdbID         := [0-9][a-zA-Z0-9]{3} chainID       := [a-zA-Z0-9] scopID        := 'd' pdbID [a-z_][0-9_] resNum        := [-+]?[0-9]+[A-Za-z]? Example structures: 1TIM     #whole structure 4HHB.C     #single chain 4GCR.A_1-83     #one domain, by residue number 3AA0.A,B     #two chains treated as one structure d2bq6a1     #scop domain </pre> With the additional set of rules: <ul> <li>If only a PDB code is provided, the whole structure will be return including ligands, but the first model only (for NMR). <li>Chain IDs are case sensitive, PDB ids are not. To specify a particular chain write as: 4hhb.A or 4HHB.A </li> <li>To specify a SCOP domain write a scopId e.g. d2bq6a1. Some flexibility can be allowed in SCOP domain names, see   {@link #setStrictSCOP(boolean)}</li> <li>URLs are accepted as well</li> </ul>
 * @param name
 * @return a Structure object, or null if name appears improperly formated (eg too short, etc)
 * @throws IOException The PDB file cannot be cached due to IO errors
 * @throws StructureException The name appeared valid but did not correspond to a structure.Also thrown by some submethods upon errors, eg for poorly formatted subranges.
 */
public Structure getStructure(String name) throws IOException, StructureException {
  if (name.length() < 4)   throw new IllegalArgumentException("String_Node_Str");
  Structure n=null;
  boolean useChainNr=false;
  boolean useDomainInfo=false;
  String range=null;
  int chainNr=-1;
  try {
    String pdbId=null;
    String chainId=null;
    if (name.length() == 4) {
      pdbId=name;
    }
 else     if (name.startsWith("String_Node_Str")) {
      return getStructureFromSCOPDomain(name);
    }
 else     if (name.length() == 6) {
      pdbId=name.substring(0,4);
      if (name.substring(4,5).equals(CHAIN_SPLIT_SYMBOL)) {
        chainId=name.substring(5,6);
      }
 else       if (name.substring(4,5).equals(CHAIN_NR_SYMBOL)) {
        useChainNr=true;
        chainNr=Integer.parseInt(name.substring(5,6));
      }
    }
 else     if ((name.length() > 6) && (!name.startsWith(PDP_DOMAIN_IDENTIFIER)) && (name.contains(CHAIN_NR_SYMBOL) || name.contains(UNDERSCORE))&& (!(name.startsWith("String_Node_Str") || name.startsWith("String_Node_Str")))) {
      pdbId=name.substring(0,4);
      useDomainInfo=true;
      range=name.substring(5);
    }
 else     if (name.startsWith("String_Node_Str") || name.startsWith("String_Node_Str")) {
      try {
        URL url=new URL(name);
        return getStructureFromURL(url);
      }
 catch (      Exception e) {
        e.printStackTrace();
        return null;
      }
    }
 else     if (name.startsWith(PDP_DOMAIN_IDENTIFIER)) {
      try {
        return getPDPStructure(name);
      }
 catch (      Exception e) {
        e.printStackTrace();
        return null;
      }
    }
    if (pdbId == null) {
      return null;
    }
    while (checkLoading(pdbId)) {
      try {
        Thread.sleep(100);
      }
 catch (      InterruptedException e) {
        System.err.println(e.getMessage());
      }
    }
    Structure s;
    flagLoading(pdbId);
    try {
      PDBFileReader reader=new PDBFileReader();
      reader.setPath(path);
      reader.setPdbDirectorySplit(isSplit);
      reader.setAutoFetch(autoFetch);
      reader.setFetchFileEvenIfObsolete(fetchFileEvenIfObsolete);
      reader.setFetchCurrent(fetchCurrent);
      reader.setFileParsingParameters(params);
      s=reader.getStructureById(pdbId.toLowerCase());
    }
 catch (    Exception e) {
      flagLoadingFinished(pdbId);
      throw new StructureException(e.getMessage() + "String_Node_Str" + pdbId,e);
    }
    flagLoadingFinished(pdbId);
    if (chainId == null && chainNr < 0 && range == null) {
      n=StructureTools.getReducedStructure(s,-1);
    }
 else {
      if (useChainNr) {
        n=StructureTools.getReducedStructure(s,chainNr);
      }
 else       if (useDomainInfo) {
        n=StructureTools.getSubRanges(s,range);
      }
 else {
        n=StructureTools.getReducedStructure(s,chainId);
      }
    }
  }
 catch (  Exception e) {
    e.printStackTrace();
    throw new StructureException(e.getMessage() + "String_Node_Str" + name,e);
  }
  n.setName(name);
  return n;
}