Commits

Daniel Lowe committed 73a8338

Fixed bug where hydrogen radicals were being incorrectly output when using wilcards.

Comments (0)

Files changed (2)

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

 			if (neighbours.size() > 1){
 				return false;
 			}
-			//special case where hydrogen is a counter ion or only connects to other hydrogen
-			boolean foundNonHydrogenNeighbour =false;
+			//special case where hydrogen is a counter ion or only connects to other hydrogen and/or R-groups
+			boolean foundHeavyAtomNeighbour =false;
 			for (Atom neighbour : neighbours) {
-				if (!neighbour.getElement().equals("H")){
-					foundNonHydrogenNeighbour =true;
+				String element = neighbour.getElement();
+				if (!element.equals("H") && !element.equals("R")){
+					foundHeavyAtomNeighbour =true;
 				}
 			}
-			if (!foundNonHydrogenNeighbour){
+			if (!foundHeavyAtomNeighbour){
 				return false;
 			}
 			

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

 	}
 	
 	@Test
-	public void testRGroup() throws StructureBuildingException {
+	public void testRGroup1() throws StructureBuildingException {
 		Fragment f = state.fragManager.buildSMILES("[R]CC[R]");
 		StructureBuilder.makeHydrogensExplicit(state);
 		String smiles = new SMILESWriter(f).generateSmiles();
 	}
 	
 	@Test
+	public void testRGroup2() throws StructureBuildingException {
+		Fragment f = state.fragManager.buildSMILES("[H][R]");
+		StructureBuilder.makeHydrogensExplicit(state);
+		String smiles = new SMILESWriter(f).generateSmiles();
+		assertEquals("[H]*", smiles);
+	}
+	
+	@Test
 	public void testRingOpeningsGreaterThan10() throws StructureBuildingException {
 		Fragment f = state.fragManager.buildSMILES("C12=C3C4=C5C6=C1C7=C8C9=C1C%10=C%11C(=C29)C3=C2C3=C4C4=C5C5=C9C6=C7C6=C7C8=C1C1=C8C%10=C%10C%11=C2C2=C3C3=C4C4=C5C5=C%11C%12=C(C6=C95)C7=C1C1=C%12C5=C%11C4=C3C3=C5C(=C81)C%10=C23");
 		StructureBuilder.makeHydrogensExplicit(state);