Skip to content

Commit

Permalink
Merge pull request #1058 from xcalibur91/master
Browse files Browse the repository at this point in the history
Refactoring : Extract method getBackboneAtomArray changes to reduce the cyclomatic complexity
  • Loading branch information
josemduarte committed Apr 6, 2023
2 parents c573d5b + a135683 commit 27a5799
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 69 deletions.
Expand Up @@ -167,6 +167,9 @@ public class StructureTools {

private static final Set<Element> hBondDonorAcceptors;

private static final Set<String> NUCLEOTIDE_BACKBONE_ATOMS;
private static final Set<String> AMINOACID_BACKBONE_ATOMS;

static {
nucleotides30 = new HashMap<String, Character>();
nucleotides30.put("DA", 'A');
Expand Down Expand Up @@ -256,6 +259,9 @@ public class StructureTools {
hBondDonorAcceptors.add(Element.O);
hBondDonorAcceptors.add(Element.S);

NUCLEOTIDE_BACKBONE_ATOMS = new HashSet<>(Arrays.asList(C1_ATOM_NAME, C2_ATOM_NAME, C3_ATOM_NAME, C4_ATOM_NAME, O2_ATOM_NAME, O3_ATOM_NAME, O4_ATOM_NAME, O5_ATOM_NAME, OP1_ATOM_NAME, OP2_ATOM_NAME, P_ATOM_NAME));
AMINOACID_BACKBONE_ATOMS = new HashSet<>(Arrays.asList(CA_ATOM_NAME, C_ATOM_NAME, N_ATOM_NAME, O_ATOM_NAME));

}

/**
Expand Down Expand Up @@ -1128,65 +1134,36 @@ public static Atom[] getRepresentativeAtomArray(Structure s) {
* @return an Atom[] array
*/
public static Atom[] getBackboneAtomArray(Structure s) {

List<Atom> atoms = new ArrayList<>();

for (Chain c : s.getChains()) {
for (Group g : c.getAtomGroups()) {
if (g.hasAminoAtoms()) {
// this means we will only take atoms grom groups that have
// complete backbones
for (Atom a : g.getAtoms()) {
switch (g.getType()) {
case NUCLEOTIDE:
// Nucleotide backbone
if (a.getName().equals(C1_ATOM_NAME))
atoms.add(a);
if (a.getName().equals(C2_ATOM_NAME))
atoms.add(a);
if (a.getName().equals(C3_ATOM_NAME))
atoms.add(a);
if (a.getName().equals(C4_ATOM_NAME))
atoms.add(a);
if (a.getName().equals(O2_ATOM_NAME))
atoms.add(a);
if (a.getName().equals(O3_ATOM_NAME))
atoms.add(a);
if (a.getName().equals(O4_ATOM_NAME))
atoms.add(a);
if (a.getName().equals(O5_ATOM_NAME))
atoms.add(a);
if (a.getName().equals(OP1_ATOM_NAME))
atoms.add(a);
if (a.getName().equals(OP2_ATOM_NAME))
atoms.add(a);
if (a.getName().equals(P_ATOM_NAME))
atoms.add(a);
// TODO Allow C4* names as well as C4'? -SB 3/2015
break;
case AMINOACID:
default:
// 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(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);
break;
}
if (g.getType() == GroupType.NUCLEOTIDE) {
addNucleotideAndAminoAtoms(atoms, g, NUCLEOTIDE_BACKBONE_ATOMS);
} else {
addNucleotideAndAminoAtoms(atoms, g, AMINOACID_BACKBONE_ATOMS);
}
}
}

}

return atoms.toArray(new Atom[0]);
}

/**
* This method will be used to add the Nucleotide and Amino atoms to the backbone Atom arrays based on the pre-defined Atom names.
* @param atoms
* @param g
* @param atomNames
*/
private static void addNucleotideAndAminoAtoms(List<Atom> atoms, Group g, Set<String> atomNames) {
for (Atom a : g.getAtoms()) {
if (atomNames.contains(a.getName())) {
atoms.add(a);
}
}
}


/**
* Convert three character amino acid codes into single character e.g.
* convert CYS to C. Valid 3-letter codes will be those of the standard 20
Expand Down
Expand Up @@ -616,10 +616,7 @@ public double getContactOverlapScore(StructureInterface other, boolean invert) {
Pair<EntityInfo> thisCompounds = new Pair<EntityInfo>(thisChains.getFirst().getEntityInfo(), thisChains.getSecond().getEntityInfo());
Pair<EntityInfo> otherCompounds = new Pair<EntityInfo>(otherChains.getFirst().getEntityInfo(), otherChains.getSecond().getEntityInfo());

if ( ( (thisCompounds.getFirst().getMolId() == otherCompounds.getFirst().getMolId()) &&
(thisCompounds.getSecond().getMolId() == otherCompounds.getSecond().getMolId()) ) ||
( (thisCompounds.getFirst().getMolId() == otherCompounds.getSecond().getMolId()) &&
(thisCompounds.getSecond().getMolId() == otherCompounds.getFirst().getMolId()) ) ) {
if (checkMolIdMatch(thisCompounds,otherCompounds)) {

int common = 0;
GroupContactSet thisContacts = getGroupContacts();
Expand Down Expand Up @@ -653,6 +650,17 @@ public double getContactOverlapScore(StructureInterface other, boolean invert) {
}
}

/**
* This method check if two compounds have same MolIds or not.
* @param thisCompounds
* @param otherCompounds
* @return
*/
private boolean checkMolIdMatch(Pair<EntityInfo> thisCompounds, Pair<EntityInfo> otherCompounds){
boolean firstMatch = thisCompounds.getFirst().getMolId() == otherCompounds.getFirst().getMolId() && thisCompounds.getSecond().getMolId() == otherCompounds.getSecond().getMolId();
boolean secondMatch = thisCompounds.getFirst().getMolId() == otherCompounds.getSecond().getMolId() && thisCompounds.getSecond().getMolId() == otherCompounds.getFirst().getMolId();
return firstMatch || secondMatch;
}
public GroupContactSet getGroupContacts() {
if (groupContacts==null) {
this.groupContacts = new GroupContactSet(contacts);
Expand Down
Expand Up @@ -180,26 +180,29 @@ public boolean isIdentity() {
*/
public boolean isPureTranslation() {
if (isPureCrystalTranslation()) return true;
if (SpaceGroup.deltaComp(matTransform.m00,1,SpaceGroup.DELTA) &&
SpaceGroup.deltaComp(matTransform.m01,0,SpaceGroup.DELTA) &&
SpaceGroup.deltaComp(matTransform.m02,0,SpaceGroup.DELTA) &&

SpaceGroup.deltaComp(matTransform.m10,0,SpaceGroup.DELTA) &&
SpaceGroup.deltaComp(matTransform.m11,1,SpaceGroup.DELTA) &&
SpaceGroup.deltaComp(matTransform.m12,0,SpaceGroup.DELTA) &&

SpaceGroup.deltaComp(matTransform.m20,0,SpaceGroup.DELTA) &&
SpaceGroup.deltaComp(matTransform.m21,0,SpaceGroup.DELTA) &&
SpaceGroup.deltaComp(matTransform.m22,1,SpaceGroup.DELTA) &&
( Math.abs(matTransform.m03-0.0)>SpaceGroup.DELTA ||
Math.abs(matTransform.m13-0.0)>SpaceGroup.DELTA ||
Math.abs(matTransform.m23-0.0)>SpaceGroup.DELTA)) {
return true;
}

if (isPureMatrixTranslation()) return true;
return false;
}

/**
* This method will help check if the matrix translation is pure or not.
* @return boolean
*/
private boolean isPureMatrixTranslation(){
return SpaceGroup.deltaComp(matTransform.m00,1,SpaceGroup.DELTA) &&
SpaceGroup.deltaComp(matTransform.m01,0,SpaceGroup.DELTA) &&
SpaceGroup.deltaComp(matTransform.m02,0,SpaceGroup.DELTA) &&

SpaceGroup.deltaComp(matTransform.m10,0,SpaceGroup.DELTA) &&
SpaceGroup.deltaComp(matTransform.m11,1,SpaceGroup.DELTA) &&
SpaceGroup.deltaComp(matTransform.m12,0,SpaceGroup.DELTA) &&

SpaceGroup.deltaComp(matTransform.m20,0,SpaceGroup.DELTA) &&
SpaceGroup.deltaComp(matTransform.m21,0,SpaceGroup.DELTA) &&
SpaceGroup.deltaComp(matTransform.m22,1,SpaceGroup.DELTA) &&
(Math.abs(matTransform.m03-0.0)>SpaceGroup.DELTA || Math.abs(matTransform.m13-0.0)>SpaceGroup.DELTA || Math.abs(matTransform.m23-0.0)>SpaceGroup.DELTA);
}

/**
* Tells whether this transformation contains a fractional translational
* component (whatever its rotational component). A fractional translation
Expand Down

0 comments on commit 27a5799

Please sign in to comment.