@@ -119,12 +119,12 @@ def convert_yaml(yaml_filename, ffxml_dir):
119119 if name_collisions :
120120 raise ValueError (f"Collision between residue/patch names { sorted (name_collisions )} " )
121121
122- # Ensure that no atom names contain hyphens, as this will confuse the
123- # improper handling script (by the time these names reach the script,
124- # they will have been prepended with residue or patch names joined with
125- # a hyphen).
122+ # Ensure that no names contain hyphens, as this will confuse the
123+ # improper/anisotropy handling scripts.
126124 for templates in (params .residues .values (), params .patches .values ()):
127125 for template in templates :
126+ if "-" in template .name :
127+ raise ValueError (f"Forbidden character in template { template .name } " )
128128 for atom in template .atoms :
129129 if "-" in atom .name :
130130 raise ValueError (f"Forbidden character in template { template .name } atom { atom .name } " )
@@ -485,13 +485,13 @@ def preprocess_improper_types(improper_types, prepare_parameters):
485485
486486 script = etree .SubElement (ffxml_tree .getroot (), "Script" )
487487 script .text = script_template .format (
488- residue_impropers = repr (residue_impropers ),
489- patch_impropers = repr (patch_impropers ),
490- delete_impropers = repr (delete_impropers ),
491- residue_order = repr (residue_order ),
492- patch_order = repr (patch_order ),
493- periodic_improper_types = repr (periodic_improper_types ),
494- harmonic_improper_types = repr (harmonic_improper_types ),
488+ residue_impropers = format_dict (residue_impropers ),
489+ patch_impropers = format_dict (patch_impropers ),
490+ delete_impropers = format_dict (delete_impropers ),
491+ residue_order = format_dict (residue_order ),
492+ patch_order = format_dict (patch_order ),
493+ periodic_improper_types = format_dict (periodic_improper_types ),
494+ harmonic_improper_types = format_dict (harmonic_improper_types ),
495495 )
496496
497497
@@ -533,13 +533,17 @@ def preprocess_template_anisotropies(template_anisotropies):
533533
534534 script = etree .SubElement (ffxml_tree .getroot (), "Script" )
535535 script .text = script_template .format (
536- residue_anisotropies = repr (residue_anisotropies ),
537- patch_anisotropies = repr (patch_anisotropies ),
538- delete_anisotropies = repr (delete_anisotropies ),
539- residue_order = repr (residue_order ),
540- patch_order = repr (patch_order ),
536+ residue_anisotropies = format_dict (residue_anisotropies ),
537+ patch_anisotropies = format_dict (patch_anisotropies ),
538+ delete_anisotropies = format_dict (delete_anisotropies ),
539+ residue_order = format_dict (residue_order ),
540+ patch_order = format_dict (patch_order ),
541541 )
542542
543543
544+ def format_dict (d ):
545+ return "\n " .join (["{" ] + [f" { k !r} : { v !r} ," for k , v in d .items ()] + ["}" ])
546+
547+
544548if __name__ == "__main__" :
545549 main ()
0 commit comments