2791 """Translate the file given on the command line."""
2794 DEBUG(
'translate',
"+++ Loaded model")
2797 for config_file
in options.config_file:
2798 config.read_configuration_file(config_file)
2799 DEBUG(
'translate',
"+++ Read config")
2802 if options.protocol:
2804 protocol.apply_protocol_file(doc, options.protocol)
2806 post_proto_cellml = options.outfilename
or model_file
2807 post_proto_cellml = os.path.splitext(post_proto_cellml)[0] +
'-proto.cellml.ppp'
2809 doc.xml(indent=
u'yes', stream=stream)
2811 DEBUG(
'translate',
"+++ Applied protocol")
2813 config.finalize_config()
2814 DEBUG(
'translate',
"+++ Processed config")
2819 translator_klass = CellMLTranslator.translators[options.translate_type]
2820 if not options.protocol:
2821 translator_klass.generate_interface(doc, solver_info)
2822 config.validate_metadata(options.assume_valid)
2823 DEBUG(
'translate',
"+++ Generated interface")
2826 config.find_lookup_variables()
2827 DEBUG(
'translate',
"+++ Found LT keys")
2832 config.annotate_currents_for_pe()
2834 config.annotate_metadata_for_pe()
2835 DEBUG(
'translate',
"+++ Annotated variables")
2837 config.expose_variables()
2839 class_name = options.class_name
2841 class_name = doc.model.name.replace(
'-',
'_')
2842 if options.augment_class_name:
2843 class_name =
u'CML_' + class_name
2847 class_name +=
'_lut'
2848 if options.backward_euler:
2850 if options.use_modifiers:
2851 class_name +=
'_sens'
2852 if options.protocol:
2854 class_name +=
"_Proto_" + os.path.splitext(os.path.basename(options.protocol))[0]
2856 output_filename = getattr(options,
'outfilename',
None)
2857 if not options.translate
and not output_filename:
2858 output_filename =
'stdout'
2860 if options.units_conversions:
2861 doc.model.add_units_conversions()
2862 DEBUG(
'translate',
"+++ Added units conversions")
2864 if options.do_jacobian_analysis:
2866 lin.analyse_for_jacobian(doc, V=config.V_variable)
2867 DEBUG(
'translate',
"+++ Analysed model for Jacobian")
2869 if options.maple_output:
2871 from maple_parser
import MapleParser
2873 jacobian_file = file(options.maple_output)
2874 doc.model._cml_jacobian = mp.parse(jacobian_file)
2875 doc.model._cml_jacobian_full = mp.JacobianWasFullSize
2876 jacobian_file.close()
2877 if not options.backward_euler
and doc.model._cml_jacobian_full:
2879 solver_info.add_jacobian_matrix()
2880 solver_info.add_variable_links()
2882 if options.backward_euler:
2885 lin.analyse_for_jacobian(doc, V=config.V_variable)
2886 lin.rearrange_linear_odes(doc)
2888 jacobian = doc.model._cml_jacobian
2889 if isinstance(jacobian, tuple):
2890 assert doc.model._cml_jacobian_full
2891 jacobian = jacobian[1]
2892 nonlinear_vars = set([v.get_source_variable(recurse=
True)
for v
in doc.model._cml_nonlinear_system_variables])
2894 return cellml_variable.get_variable_object(doc.model, vname).get_source_variable(recurse=
True)
2895 for var_i, var_j
in jacobian.keys():
2896 if gv(var_i)
not in nonlinear_vars
or gv(var_j)
not in nonlinear_vars:
2897 del jacobian[(var_i, var_j)]
2898 if doc.model._cml_jacobian_full:
2901 for key, expr
in jacobian.iteritems():
2903 if key[0] == key[1]:
2905 new_expr = maple_parser.MNumber([
'1'])
2906 if not (isinstance(expr, maple_parser.MNumber)
and str(expr) ==
'0'):
2910 args.append(new_expr)
2911 args.append(maple_parser.MOperator([maple_parser.MVariable([
'delta_t']), expr],
'prod',
'times'))
2912 new_expr = maple_parser.MOperator(args,
'',
'minus')
2914 jacobian[key] = new_expr
2916 solver_info.add_all_info()
2918 solver_info.add_variable_links()
2919 solver_info.add_linear_ode_update_equations()
2920 DEBUG(
'translate',
"+++ Parsed and incorporated Maple output")
2922 options.include_dt_in_tables =
False
2933 pe.parteval(doc, solver_info, lut)
2934 DEBUG(
'translate',
"+++ Done PE")
2938 lut.analyse_model(doc, solver_info)
2939 DEBUG(
'translate',
"+++ Done LT analysis")
2941 if options.rush_larsen:
2943 rl.analyse_model(doc)
2944 DEBUG(
'translate',
"+++ Done Rush-Larsen analysis")
2946 if options.translate:
2948 initargs = {
'add_timestamp':
not options.no_timestamp,
2950 transargs = {
'v_variable': config.V_variable}
2951 transargs[
'row_lookup_method'] = options.row_lookup_method
2952 transargs[
'lt_index_uses_floor'] = options.lt_index_uses_floor
2953 transargs[
'constrain_table_indices'] = options.constrain_table_indices
2954 """if issubclass(translator_klass, CellMLToMapleTranslator):
2955 initargs['omit_constants'] = options.omit_constants
2956 initargs['compute_full_jacobian'] = options.compute_full_jacobian
2958 from CellMLToNektarTranslator
import CellMLToNektarTranslator
2959 if issubclass(translator_klass, CellMLToNektarTranslator):
2960 solver_info.add_membrane_ionic_current()
2961 transargs[
'use_chaste_stimulus'] = options.use_chaste_stimulus
2962 transargs[
'separate_lut_class'] = options.separate_lut_class
2963 transargs[
'convert_interfaces'] = options.convert_interfaces
2964 transargs[
'use_modifiers'] = options.use_modifiers
2965 transargs[
'use_data_clamp'] = options.use_data_clamp
2966 transargs[
'dynamically_loadable'] = options.dynamically_loadable
2967 transargs[
'use_protocol'] = bool(options.protocol)
2968 t = translator_klass(**initargs)
2969 t.translate(doc, model_file, output_filename, class_name=class_name, **transargs)
2970 cellml_metadata.remove_model(doc.model)
2975 doc.xml_insert_before(doc.model, comment)
2978 doc.xml(indent=
u'yes', stream=stream)
2982 DEBUG(
'translate',
"+++ Done translation")