Exemplo n.º 1
0
        protected static BiasingParameters.ReactionInfo ReadReactionInformation(JObject reaction, int intermediateRareEventCount)
        {
            var reactionInfo = new BiasingParameters.ReactionInfo {
                Name = (string)reaction["NAME"]
            };
            var rareEventInfoArray = (JArray)reaction["RARE_EVENT_INFO"];

            if (rareEventInfoArray.Count != intermediateRareEventCount)
            {
                throw new RareEventInfoArrayLengthException(string.Format("JSON data for reaction '{0}' invalid, RARE_EVENT_INFO array length doesn't match IRE_COUNT.", reactionInfo.Name), reactionInfo.Name);
            }
            foreach (var rareEventInfo in from JObject eventInfo in rareEventInfoArray select ReadRareEventInfo(eventInfo, reactionInfo))
            {
                reactionInfo.RareEvents.Add(rareEventInfo);
            }

            return(reactionInfo);
        }
        protected static void WriteReactionInformation(BiasingParameters.ReactionInfo reaction, StringBuilder builder)
        {
            builder.AppendLine("                {");
            builder.AppendFormat("                \"NAME\" : \"{0}\",", reaction.Name).AppendLine();
            builder.AppendLine("                \"RARE_EVENT_INFO\" : [");
            int count = 0;

            foreach (var rareEvent in reaction.RareEvents)
            {
                WriteRareEventInfo(rareEvent, builder);
                if (++count < reaction.RareEvents.Count)
                {
                    builder.AppendLine(",");
                }
                else
                {
                    builder.AppendLine();
                }
            }
            builder.AppendLine("                    ]");
            builder.Append("                }");
        }
Exemplo n.º 3
0
        protected static BiasingParameters.RareEventInfo ReadRareEventInfo(JObject eventInfo, BiasingParameters.ReactionInfo reactionInfo)
        {
            var rareEventInfo = new BiasingParameters.RareEventInfo {
                BinCount = (int)eventInfo["BIN_COUNT"]
            };
            var gammasArray = (JArray)eventInfo["GAMMAS"];

            if (gammasArray.Count != rareEventInfo.BinCount)
            {
                throw new GammaArrayLengthException(string.Format("JSON data for reaction '{0}' invalid, GAMMAS array length doesn't match BIN_COUNT.", reactionInfo.Name), reactionInfo.Name);
            }
            for (var i = 0; i < rareEventInfo.BinCount; i++)
            {
                rareEventInfo.Gammas[i] = (double)gammasArray[i];
            }
            var cutoffArray = (JArray)eventInfo["CUTOFF"];

            if (cutoffArray.Count != (rareEventInfo.BinCount - 1) && rareEventInfo.BinCount > 1)
            {
                throw new CutoffArrayLengthException(string.Format("JSON data for reaction '{0}' invalid, CUTOFF array length doesn't match BIN_COUNT - 1.", reactionInfo.Name), reactionInfo.Name);
            }
            if (rareEventInfo.BinCount == 1)
            {
                rareEventInfo.Thresholds[0] = (int)cutoffArray[0];
            }
            else
            {
                for (var j = 0; j < rareEventInfo.BinCount - 1; j++)
                {
                    rareEventInfo.Thresholds[j] = (double)cutoffArray[j];
                }
            }
            return(rareEventInfo);
        }