Commits

Daniel Lowe  committed 08db1b2

Locanted phospho now prefers hydroxy groups
Added units tests for phospho substitution

  • Participants
  • Parent commits 588466e

Comments (0)

Files changed (2)

File opsin-core/src/main/java/uk/ac/cam/ch/wwmm/opsin/StructureBuildingMethods.java

 					joinFragmentsAdditively(state, frag, parentFrag);
 				}
 				else{
-					joinFragmentsSubstitutively(state, frag, parentFrag.getAtomByLocantOrThrow(locantString));
+					Atom atomToSubstituteAt = parentFrag.getAtomByLocantOrThrow(locantString);
+					if (PHOSPHO_SUBTYPE_VAL.equals(group.getAttributeValue(SUBTYPE_ATR)) && frag.getOutAtom(0).getValency() == 1){
+						if (!atomToSubstituteAt.getElement().equals("O")){
+							for (Atom neighbour : atomToSubstituteAt.getAtomNeighbours()) {
+								if (neighbour.getElement().equals("O") &&
+										neighbour.getBonds().size()==1 &&
+										neighbour.getCharge() == 0){
+									atomToSubstituteAt = neighbour;
+									break;
+								}
+							}
+						}
+					}
+					joinFragmentsSubstitutively(state, frag, atomToSubstituteAt);
 				}
 			}
 		}

File opsin-core/src/test/java/uk/ac/cam/ch/wwmm/opsin/StructureBuildingMethodsTest.java

 package uk.ac.cam.ch.wwmm.opsin;
 
+import java.util.Set;
+
 import org.junit.Test;
 
 import nu.xom.Attribute;
 import nu.xom.Element;
 import static uk.ac.cam.ch.wwmm.opsin.XmlDeclarations.*;
 import static junit.framework.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
 
 public class StructureBuildingMethodsTest {
 	
 		assertEquals("4", StructureBuildingMethods.checkForBracketedPrimedLocantSpecialCase(substituent, "4'"));
 		assertEquals(null, StructureBuildingMethods.checkForBracketedPrimedLocantSpecialCase(substituent, "4''"));
 	}
+	
+	@Test
+	public void notPhosphoSubstitution() throws StructureBuildingException {
+		//standard unlocanted substitution
+		BuildState state = new BuildState(mock(NameToStructureConfig.class), new SMILESFragmentBuilder(), mock(CMLFragmentBuilder.class));
+		Element word = new Element(WORD_EL);
+		
+		Element amino = new Element(GROUP_EL);
+		Fragment aminoFrag = state.fragManager.buildSMILES("-N");
+		state.xmlFragmentMap.put(amino, aminoFrag);
+		Element substituent = new Element(SUBSTITUENT_EL);
+		substituent.appendChild(amino);
+		
+		Element methanol = new Element(GROUP_EL);
+		state.xmlFragmentMap.put(methanol, state.fragManager.buildSMILES("CO"));
+		Element root = new Element(ROOT_EL);
+		root.appendChild(methanol);
+
+		word.appendChild(substituent);
+		word.appendChild(root);
+		StructureBuildingMethods.resolveRootOrSubstituentUnLocanted(state, substituent);
+		
+		Set<Bond> interFragmentBonds =  state.fragManager.getInterFragmentBonds(aminoFrag);
+		assertEquals(1, interFragmentBonds.size());
+		assertEquals("C", interFragmentBonds.iterator().next().getOtherAtom(aminoFrag.getFirstAtom()).getElement());
+	}
+	
+	@Test
+	public void phosphoUnlocantedSubstitution() throws StructureBuildingException {
+		BuildState state = new BuildState(mock(NameToStructureConfig.class), new SMILESFragmentBuilder(), mock(CMLFragmentBuilder.class));
+		Element word = new Element(WORD_EL);
+		
+		Element phospho = new Element(GROUP_EL);
+		phospho.addAttribute(new Attribute(SUBTYPE_ATR, PHOSPHO_SUBTYPE_VAL));
+		Fragment phosphoFrag = state.fragManager.buildSMILES("-P(=O)O");
+		state.xmlFragmentMap.put(phospho, phosphoFrag);
+		Element substituent = new Element(SUBSTITUENT_EL);
+		substituent.appendChild(phospho);
+		
+		Element methanol = new Element(GROUP_EL);
+		state.xmlFragmentMap.put(methanol, state.fragManager.buildSMILES("CO"));
+		Element root = new Element(ROOT_EL);
+		root.appendChild(methanol);
+
+		word.appendChild(substituent);
+		word.appendChild(root);
+		StructureBuildingMethods.resolveRootOrSubstituentUnLocanted(state, substituent);
+		
+		Set<Bond> interFragmentBonds =  state.fragManager.getInterFragmentBonds(phosphoFrag);
+		assertEquals(1, interFragmentBonds.size());
+		assertEquals("O", interFragmentBonds.iterator().next().getOtherAtom(phosphoFrag.getFirstAtom()).getElement());
+	}
+	
+	@Test
+	public void phosphoLocantedSubstitution() throws StructureBuildingException {
+		BuildState state = new BuildState(mock(NameToStructureConfig.class), new SMILESFragmentBuilder(), mock(CMLFragmentBuilder.class));
+		Element word = new Element(WORD_EL);
+		
+		Element phospho = new Element(GROUP_EL);
+		phospho.addAttribute(new Attribute(SUBTYPE_ATR, PHOSPHO_SUBTYPE_VAL));
+		Fragment phosphoFrag = state.fragManager.buildSMILES("-P(=O)O");
+		state.xmlFragmentMap.put(phospho, phosphoFrag);
+		Element substituent = new Element(SUBSTITUENT_EL);
+		substituent.addAttribute(new Attribute(LOCANT_ATR, "4"));
+		substituent.appendChild(phospho);
+		
+		Element methanol = new Element(GROUP_EL);
+		state.xmlFragmentMap.put(methanol, state.fragManager.buildSMILES("CCCCO","group","1/2/3/4/"));
+		Element root = new Element(ROOT_EL);
+		root.appendChild(methanol);
+
+		word.appendChild(substituent);
+		word.appendChild(root);
+		StructureBuildingMethods.resolveRootOrSubstituentLocanted(state, substituent);
+		
+		Set<Bond> interFragmentBonds =  state.fragManager.getInterFragmentBonds(phosphoFrag);
+		assertEquals(1, interFragmentBonds.size());
+		assertEquals("O", interFragmentBonds.iterator().next().getOtherAtom(phosphoFrag.getFirstAtom()).getElement());
+	}
 }