Skip to content

Commit

Permalink
Full fix for biojava#148, all tests pass
Browse files Browse the repository at this point in the history
- some improvement in exceptions and logging biojava#111 and biojava#155
  • Loading branch information
josemduarte committed Sep 20, 2014
1 parent e43e187 commit 6b50276
Show file tree
Hide file tree
Showing 20 changed files with 133 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static interface GroupMatcher {
@Override
public boolean matches(Group group) {
ResidueType type = group.getChemComp().getResidueType();
return group.hasAtom(StructureTools.caAtomName) || AMINO_ACID_NAMES.contains(group.getPDBName()) || type == ResidueType.lPeptideLinking || type == ResidueType.glycine || type == ResidueType.lPeptideAminoTerminus || type == ResidueType.lPeptideCarboxyTerminus || type == ResidueType.dPeptideLinking || type == ResidueType.dPeptideAminoTerminus || type == ResidueType.dPeptideCarboxyTerminus;
return group.hasAtom(StructureTools.CA_ATOM_NAME) || AMINO_ACID_NAMES.contains(group.getPDBName()) || type == ResidueType.lPeptideLinking || type == ResidueType.glycine || type == ResidueType.lPeptideAminoTerminus || type == ResidueType.lPeptideCarboxyTerminus || type == ResidueType.dPeptideLinking || type == ResidueType.dPeptideAminoTerminus || type == ResidueType.dPeptideCarboxyTerminus;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ public boolean hasAminoAtoms(){
// if this method call is performed too often, it should become a
// private method and provide a flag for Group object ...

if ( hasAtom(StructureTools.caAtomName) &&
hasAtom(StructureTools.cAtomName) &&
hasAtom(StructureTools.nAtomName) &&
hasAtom(StructureTools.oAtomName)) {
if ( hasAtom(StructureTools.CA_ATOM_NAME) &&
hasAtom(StructureTools.C_ATOM_NAME) &&
hasAtom(StructureTools.N_ATOM_NAME) &&
hasAtom(StructureTools.O_ATOM_NAME)) {

// this is the minimun requirement for something to be considered an aminoacid with a backbone
// note that if the backbone is incomplete it won't be considered an aminoacid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,31 @@ public class StructureTools {
private static final Logger logger = LoggerFactory.getLogger(StructureTools.class);

/**
* The atom name of the C-alpha atom
* The atom name of the backbone C-alpha atom.
* Note that this can be ambiguous depending on the context since Calcium atoms
* use the same name in PDB.
*/
public static final String caAtomName = "CA";
public static final String CA_ATOM_NAME = "CA";

/**
* The atom name for the amide nitrogen
* The atom name for the backbone amide nitrogen
*/
public static final String nAtomName = "N";
public static final String N_ATOM_NAME = "N";

/**
* The atom name for the carbonyl carbon
* The atom name for the backbone carbonyl
*/
public static final String cAtomName = "C";
public static final String C_ATOM_NAME = "C";

/**
* The atom name for the carbonyl oxygen
* The atom name for the backbone carbonyl oxygen
*/
public static final String oAtomName = "O";
public static final String O_ATOM_NAME = "O";

/**
* The atom name of the C-beta atom
* The atom name of the side-chain C-beta atom
*/
public static final String cbAtomName = "CB";
public static final String CB_ATOM_NAME = "CB";


public static final Character UNKNOWN_GROUP_LABEL = new Character('x');
Expand Down Expand Up @@ -470,8 +472,8 @@ public static final Atom[] getAtomCAArray(Chain c){
List<Atom> atoms = new ArrayList<Atom>();

for (Group g: c.getAtomGroups()) {
if (g.hasAtom(caAtomName) && g.getAtom(caAtomName).getElement()==Element.C) {
atoms.add(g.getAtom(caAtomName));
if (g.hasAtom(CA_ATOM_NAME) && g.getAtom(CA_ATOM_NAME).getElement()==Element.C) {
atoms.add(g.getAtom(CA_ATOM_NAME));
}
}

Expand Down Expand Up @@ -509,7 +511,7 @@ public static final Atom[] cloneCAArray(Atom[] ca) throws StructureException{

Group parentN = (Group)parentG.clone();

newCA[apos] = parentN.getAtom(caAtomName);
newCA[apos] = parentN.getAtom(CA_ATOM_NAME);
newChain.addGroup(parentN);
}
return newCA;
Expand Down Expand Up @@ -582,7 +584,7 @@ public static Atom[] duplicateCA2(Atom[] ca2) throws StructureException{
}

c.addGroup(g);
ca2clone[pos] = g.getAtom(caAtomName);
ca2clone[pos] = g.getAtom(CA_ATOM_NAME);

pos++;
}
Expand All @@ -606,7 +608,7 @@ public static Atom[] duplicateCA2(Atom[] ca2) throws StructureException{
}

c.addGroup(g);
ca2clone[pos] = g.getAtom(caAtomName);
ca2clone[pos] = g.getAtom(CA_ATOM_NAME);

pos++;
}
Expand All @@ -628,8 +630,8 @@ public static Atom[] getAtomCAArray(Structure s){

for (Chain c: s.getChains()) {
for (Group g: c.getAtomGroups()) {
if (g.hasAtom(caAtomName) && g.getAtom(caAtomName).getElement()==Element.C) {
atoms.add(g.getAtom(caAtomName));
if (g.hasAtom(CA_ATOM_NAME) && g.getAtom(CA_ATOM_NAME).getElement()==Element.C) {
atoms.add(g.getAtom(CA_ATOM_NAME));
}
}
}
Expand All @@ -653,10 +655,10 @@ public static Atom[] getBackboneAtomArray(Structure s){
// this means we will only take atoms grom groups that have complete backbones
for (Atom a:g.getAtoms()) {
// we do it this way instead of with g.getAtom() to be sure we always use the same order as original
if (a.getName().equals(caAtomName)) atoms.add(a);
if (a.getName().equals(cAtomName)) atoms.add(a);
if (a.getName().equals(nAtomName)) atoms.add(a);
if (a.getName().equals(oAtomName)) atoms.add(a);
if (a.getName().equals(CA_ATOM_NAME)) atoms.add(a);
if (a.getName().equals(C_ATOM_NAME)) atoms.add(a);
if (a.getName().equals(N_ATOM_NAME)) atoms.add(a);
if (a.getName().equals(O_ATOM_NAME)) atoms.add(a);
}
}
}
Expand Down Expand Up @@ -853,21 +855,25 @@ public static final Structure getReducedStructure(Structure s, int chainNr) thro



/** In addition to the functionality provided by getReducedStructure also provides a way to specify sub-regions of a structure with the following
/**
* In addition to the functionality provided by {@link #getReducedStructure(Structure, int)}
* and {@link #getReducedStructure(Structure, String)}, also provides
* a way to specify sub-regions of a structure with the following
* specification:
*
*
* ranges can be surrounded by ( and ). (but will be removed).
* ranges are specified as
* PDBresnum1 : PDBresnum2
*
* a list of ranges is separated by ,
* <p>
* <li>ranges can be surrounded by ( and ). (but will be removed).</li>
* <li>ranges are specified as
* PDBresnum1 : PDBresnum2</li>
*
* Example
* <li>a list of ranges is separated by ,</li>
* </p>
* Example
* <pre>
* 4GCR (A:1-83)
* 1CDG (A:407-495,A:582-686)
* 1CDG (A_407-495,A_582-686)
*
* </pre>
* @param s The full structure
* @param ranges A comma-seperated list of ranges, optionally surrounded by parentheses
* @return Substructure of s specified by ranges
Expand Down Expand Up @@ -934,7 +940,7 @@ public static final Structure getSubRanges(Structure s, String ranges )
if(struc.size() != 1) {
// SCOP 1.71 uses this for some proteins with multiple chains
// Print a warning in this ambiguous case
logger.warn("Multiple possible chains match '_'. Using chain %s.%n",chain.getChainID());
logger.warn("Multiple possible chains match '_'. Using chain {}",chain.getChainID());
}
} else {
// Explicit chain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ private static void cloneAtomRange(Atom[] p1, Atom[] p2, int r1, int r2)
Group g = p2[i].getGroup();
Group newG = (Group)g.clone();

p1[i] = newG.getAtom(StructureTools.caAtomName);
p1[i] = newG.getAtom(StructureTools.CA_ATOM_NAME);
Chain parentC = g.getChain();

Chain newChain = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class StrucAligParameters {


int initialK;
String[] usedAtomNames = { StructureTools.caAtomName, } ;
String[] usedAtomNames = { StructureTools.CA_ATOM_NAME, } ;

// step 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,14 @@ private double getDistanceWithSidechain(Atom ca1, Atom ca2) throws StructureExce
double dist;
Group g1 = ca1.getGroup();
Atom cb1 = null;
if ( g1.hasAtom(StructureTools.cbAtomName)) {
cb1 = g1.getAtom(StructureTools.cbAtomName);
if ( g1.hasAtom(StructureTools.CB_ATOM_NAME)) {
cb1 = g1.getAtom(StructureTools.CB_ATOM_NAME);
}
//
Group g2 = ca2.getGroup();
Atom cb2 = null;
if ( g2.hasAtom(StructureTools.cbAtomName)) {
cb2 = g2.getAtom(StructureTools.cbAtomName);
if ( g2.hasAtom(StructureTools.CB_ATOM_NAME)) {
cb2 = g2.getAtom(StructureTools.CB_ATOM_NAME);
}


Expand Down Expand Up @@ -1241,7 +1241,7 @@ private void setStrBuf(Atom[] strBuf, int i, Atom[] ca, int j) {
//TODO
Group parent = ca[j].getGroup();
int pos = 0;
String atomName = StructureTools.caAtomName;
String atomName = StructureTools.CA_ATOM_NAME;

Atom a = null;

Expand Down Expand Up @@ -1856,7 +1856,7 @@ private void rot_mol(Atom[] caA, Atom[] caB, int nse2, Matrix m , Atom shift) th

Calc.rotate( g, m);
Calc.shift( g, shift);
caB[l] = g.getAtom(" CA ");
caB[l] = g.getAtom(StructureTools.CA_ATOM_NAME);
}
}

Expand Down Expand Up @@ -1942,7 +1942,7 @@ private Atom[] getAtoms(Atom[] ca, int length, boolean clone) throws StructureE
Atom a;
if ( clone ){
Group g = (Group)ca[i].getGroup().clone();
a = g.getAtom(" CA ");
a = g.getAtom(StructureTools.CA_ATOM_NAME);
}
else {
a = ca[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,14 @@ private double getDistanceWithSidechain(Atom ca1, Atom ca2) throws StructureExce
double dist;
Group g1 = ca1.getGroup();
Atom cb1 = null;
if ( g1.hasAtom(StructureTools.cbAtomName)) {
cb1 = g1.getAtom(StructureTools.cbAtomName);
if ( g1.hasAtom(StructureTools.CB_ATOM_NAME)) {
cb1 = g1.getAtom(StructureTools.CB_ATOM_NAME);
}
//
Group g2 = ca2.getGroup();
Atom cb2 = null;
if ( g2.hasAtom(StructureTools.cbAtomName)) {
cb2 = g2.getAtom(StructureTools.cbAtomName);
if ( g2.hasAtom(StructureTools.CB_ATOM_NAME)) {
cb2 = g2.getAtom(StructureTools.CB_ATOM_NAME);
}


Expand Down Expand Up @@ -1244,7 +1244,7 @@ private void setStrBuf(Atom[] strBuf, int i, Atom[] ca, int j) {
//TODO
Group parent = ca[j].getGroup();
int pos = 0;
String atomName = StructureTools.caAtomName;
String atomName = StructureTools.CA_ATOM_NAME;

Atom a = null;

Expand Down Expand Up @@ -1936,7 +1936,7 @@ private void rot_mol(Atom[] caA, Atom[] caB, int nse2, Matrix m , Atom shift) th

Calc.rotate( g, m);
Calc.shift( g, shift);
caB[l] = g.getAtom(" CA ");
caB[l] = g.getAtom(StructureTools.CA_ATOM_NAME);
}
}

Expand Down Expand Up @@ -2028,7 +2028,7 @@ private Atom[] getAtoms(Atom[] ca, int length, boolean clone) throws StructureE
Atom a;
if ( clone ){
Group g = (Group)ca[i].getGroup().clone();
a = g.getAtom(" CA ");
a = g.getAtom(StructureTools.CA_ATOM_NAME);
}
else {
a = ca[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public AFPChain align(Atom[] ca1, Atom[] ca2, Object param) throws StructureExce
for (Atom a : ca2){
Group g = (Group)a.getGroup().clone(); // works because each group has only a CA atom

ca2clone[pos] = g.getAtom(StructureTools.caAtomName);
ca2clone[pos] = g.getAtom(StructureTools.CA_ATOM_NAME);

pos++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static void main(String[] args){
// for (Atom a : ca2){
// Group g = (Group)a.getParent().clone();
//
// ca2clone[pos] = g.getAtom(" CA ");
// ca2clone[pos] = g.getAtom(StructureTools.caAtomName);
//
// pos++;
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ public StructureAlignmentOptimizer(int b1, int end1, Atom[] c1, int b2, int end2
//cod1[i] = (Atom)a.clone();
Group parent = (Group)a.getGroup().clone();
//cod1[i].setParent(parent);
cod1[i] = parent.getAtom(StructureTools.caAtomName);
cod1[i] = parent.getAtom(StructureTools.CA_ATOM_NAME);
//cod1[i] = c1[i];
}
for(int i = 0; i < len2; i ++) {
Atom a = c2[i+b2];
//cod2[i]= (Atom)a.clone();
Group parent = (Group)a.getGroup().clone();
//cod2[i].setParent(parent);
cod2[i] = parent.getAtom(StructureTools.caAtomName);
cod2[i] = parent.getAtom(StructureTools.CA_ATOM_NAME);
//cod2[i] = c2[i];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static Chain getCAOnly(Chain chain){

for (Atom a : atoms){

if ( a.getName().equals(StructureTools.caAtomName) && a.getElement()==Element.C){
if ( a.getName().equals(StructureTools.CA_ATOM_NAME) && a.getElement()==Element.C){
// we got a CA atom in this group!
AminoAcid n = new AminoAcidImpl();
n.setPDBName(g.getPDBName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public static void main(String[] args){
}
*/
} catch (Exception e) {
} catch (IOException e) {
e.printStackTrace();
}
}
Expand Down Expand Up @@ -572,7 +572,7 @@ public InputStream getInputStreamBioAssembly(String pdbId)

InputStreamProvider isp = new InputStreamProvider();
inputStream = isp.getInputStream(fileName);
System.out.println("Loaded original PDB file as a fallback." + fileName);
logger.warn("Loaded original PDB file as a fallback." + fileName);
loadedBioAssembly = false;
return inputStream;

Expand Down Expand Up @@ -608,7 +608,7 @@ public InputStream getInputStreamBioAssembly(String pdbId)
if (bioAssemblyFallback) {
inputStream = getInputStream(pdbId);
if (inputStream != null) {
System.out.println("Biological assembly file for PDB ID: " + pdbId+ " is not available. " +
logger.warn("Biological assembly file for PDB ID: " + pdbId+ " is not available. " +
"Loaded original PDB file as a fallback from local cache.");
return getInputStream(pdbId);
}
Expand Down Expand Up @@ -660,7 +660,8 @@ private File downloadPDB(String pdbId, String pathOnServer) throws IOException

String ftp = String.format("ftp://%s%s%s/pdb%s.ent.gz", serverName,pathOnServer,middle, pdbId);

//System.out.println("Fetching " + ftp);
logger.info("Fetching {}", ftp);
logger.info("Writing to {}",realFile.toString());


URL url = new URL(ftp);
Expand Down Expand Up @@ -699,7 +700,7 @@ private File downloadPDBBiologicalAssembly(String pdbId, String pathOnServer) t

String ftp = String.format("ftp://%s%s%s/%s", serverName,pathOnServer,middle,fileName);

System.out.println("Fetching " + ftp);
logger.info("Fetching " + ftp);

URL url = null;
try {
Expand All @@ -724,7 +725,7 @@ private File downloadPDBBiologicalAssembly(String pdbId, String pathOnServer) t

if (bioAssemblyFallback) {

System.out.println("Biological unit file for PDB ID: " + pdbId+ " is not available. " +
logger.warn("Biological unit file for PDB ID: " + pdbId+ " is not available. " +
"Downloading original PDB file as a fallback.");

loadedBioAssembly = false;
Expand Down

0 comments on commit 6b50276

Please sign in to comment.