Commits

Daniel Lowe committed 9189bde

Correctly allowed mono in front of element names

  • Participants
  • Parent commits b3ec20d

Comments (0)

Files changed (2)

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

 				throw new ComponentGenerationException("\"acid\" not found after " +groupValue);
 			}
 		}
-		else if (ELEMENTARYATOM_SUBTYPE_VAL.equals(group.getAttributeValue(SUBTYPE_ATR))){
-			Element possibleMono = (Element) XOMTools.getPreviousSibling(group);
-			if (possibleMono !=null && possibleMono.getLocalName().equals(MULTIPLIER_EL) &&
-					possibleMono.getAttributeValue(VALUE_ATR).equals("1")) {
-				possibleMono.detach();//e.g. monooxygen = oxygen
-			}
-		}
-		
 		
 		if(groupValue.equals("thiophen") || groupValue.equals("selenophen") || groupValue.equals("tellurophen")) {//thiophenol is generally phenol with an O replaced with S not thiophene with a hydroxy
 			Element possibleSuffix = (Element) XOMTools.getNextSibling(group);

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

 					throw new StructureBuildingException("\"non\" probably means \"not\". If a multiplier of value 9 was intended \"nona\" should be used");
 				}
 				if (wordCount ==1){
-					throw new StructureBuildingException("Unexpected multiplier found at start of word. Perhaps the name is trivial e.g. triphosgene");
+					if (!isMonoFollowedByElement(multiplier, multiVal)){
+						throw new StructureBuildingException("Unexpected multiplier found at start of word. Perhaps the name is trivial e.g. triphosgene");
+					}
 				}
 				if (multiVal ==1){//mono
 					return;
 			}
 		}
 	}
+
+	/**
+	 * Names like monooxygen may be used to emphasise that a molecule is not being described
+	 * @param multiplier
+	 * @param multiVal
+	 * @return
+	 */
+	private boolean isMonoFollowedByElement(Element multiplier, int multiVal) {
+		if (multiVal ==1){
+			Element possibleElement = (Element) XOMTools.getNextSibling(multiplier);
+			if (possibleElement != null && possibleElement.getLocalName().equals(GROUP_EL) &&
+					(ELEMENTARYATOM_SUBTYPE_VAL.equals(possibleElement.getAttributeValue(SUBTYPE_ATR)) || possibleElement.getValue().equals("hydrogen"))){
+				return true;
+			}
+		}
+		return false;
+	}
 }