diff --git a/mosdef_gomc/formats/gmso_charmm_writer.py b/mosdef_gomc/formats/gmso_charmm_writer.py index e694ea6a..8663bddc 100755 --- a/mosdef_gomc/formats/gmso_charmm_writer.py +++ b/mosdef_gomc/formats/gmso_charmm_writer.py @@ -471,17 +471,38 @@ def unique_atom_naming( individual_atom_names_list = [] missing_bead_to_atom_name = [] for i, site in enumerate(topology.sites): - site_name = site.__dict__["name_"] + site_name_unique_naming = site.__dict__["name_"] + + # extract element or atom name from mol2 without numbers (integers) + element_name_unique_naming = "" + for site_name_unique_naming_char_i in site_name_unique_naming: + try: + int(site_name_unique_naming_char_i) + + except: + element_name_unique_naming += site_name_unique_naming_char_i + + if element_name_unique_naming == "": + raise ValueError( + "ERROR: The input file, likely mol2 file does not contain element names or char, only int." + ) + interate_thru_names = True j = 0 while interate_thru_names is True: j = j + 1 - if str(site_name)[:1] == "_": + if str(site_name_unique_naming)[:1] == "_": if ( bead_to_atom_name_dict is not None - and (str(site_name) in bead_to_atom_name_dict) is True + and (str(site_name_unique_naming) in bead_to_atom_name_dict) + is True ): - if len(bead_to_atom_name_dict[str(site_name)]) > 2: + if ( + len( + bead_to_atom_name_dict[str(site_name_unique_naming)] + ) + > 2 + ): text_to_write = ( "ERROR: only enter atom names that have 2 or less digits" + " in the Bead to atom naming dictionary (bead_to_atom_name_dict)." @@ -489,16 +510,21 @@ def unique_atom_naming( warn(text_to_write) return None, None, None else: - atom_name_value = bead_to_atom_name_dict[str(site_name)] + atom_name_value = bead_to_atom_name_dict[ + str(site_name_unique_naming) + ] no_digits_atom_name = 2 else: missing_bead_to_atom_name.append(1) atom_name_value = "BD" no_digits_atom_name = 2 - elif len(str(site_name)) > 2: - if len(str(site_name)) == 3: + elif ( + len(str(element_name_unique_naming)) > 2 + and not str(site_name_unique_naming)[:1] == "_" + ): + if len(str(element_name_unique_naming)) == 3: no_digits_atom_name = 1 - atom_name_value = site_name + atom_name_value = element_name_unique_naming else: text_to_write = ( "ERROR: atom numbering will not work propery at" @@ -508,7 +534,8 @@ def unique_atom_naming( return None, None, None else: no_digits_atom_name = 2 - atom_name_value = site_name + atom_name_value = element_name_unique_naming + atom_name_iteration = str(atom_name_value) + str( base10_to_base62_alph_num(j) ) @@ -5371,9 +5398,22 @@ def write_pdb(self, space_group="P 1"): # get other values atom_no_list.append(stuct_only_iteration.get_index(site)) + # only 2 character element names are allowed + site_name = str(site.__dict__["name_"]) + + # extract element or atom name from mol2 without numbers (integers) + if site_name[0] == "_": + element_name = site_name + else: + element_name = "" + for site_name_char_i in site_name: + try: + int(site_name_char_i) + + except: + element_name += site_name_char_i + try: - # only 2 character element names are allowed - element_name = str(site.__dict__["name_"]) # check if element is bead (i.e., first part of name "_") if element_name[0] == "_": element_name = "BD" diff --git a/mosdef_gomc/utils/files/2_ethane.mol2 b/mosdef_gomc/utils/files/2_ethane.mol2 index f4fee00e..5f7cb8e7 100644 --- a/mosdef_gomc/utils/files/2_ethane.mol2 +++ b/mosdef_gomc/utils/files/2_ethane.mol2 @@ -7,22 +7,22 @@ USER_CHARGES Energy = 0 @ATOM - 1 C 35.5140 19.2460 34.4170 C 1 ETH -0.180000 - 2 C 36.6600 18.6240 33.6370 C 1 ETH -0.180000 - 3 H 35.4340 20.3260 34.1710 H 1 ETH 0.060000 - 4 H 34.5610 18.7410 34.1540 H 1 ETH 0.060000 - 5 H 35.6970 19.1340 35.5070 H 1 ETH 0.060000 - 6 H 37.6130 19.1290 33.8990 H 1 ETH 0.060000 - 7 H 36.7400 17.5440 33.8830 H 1 ETH 0.060000 - 8 H 36.4770 18.7350 32.5470 H 1 ETH 0.060000 - 9 C 29.0900 26.1850 32.0230 C 2 ETH -0.180000 - 10 C 27.9240 27.0340 31.5460 C 2 ETH -0.180000 - 11 H 30.0320 26.7690 31.9580 H 2 ETH 0.060000 - 12 H 28.9240 25.8760 33.0760 H 2 ETH 0.060000 - 13 H 29.1790 25.2790 31.3870 H 2 ETH 0.060000 - 14 H 28.0890 27.3430 30.4920 H 2 ETH 0.060000 - 15 H 26.9810 26.4500 31.6110 H 2 ETH 0.060000 - 16 H 27.8340 27.9410 32.1810 H 2 ETH 0.060000 + 1 C1 35.5140 19.2460 34.4170 C 1 ETH -0.180000 + 2 C2 36.6600 18.6240 33.6370 C 1 ETH -0.180000 + 3 H3 35.4340 20.3260 34.1710 H 1 ETH 0.060000 + 4 H4 34.5610 18.7410 34.1540 H 1 ETH 0.060000 + 5 H5 35.6970 19.1340 35.5070 H 1 ETH 0.060000 + 6 H6 37.6130 19.1290 33.8990 H 1 ETH 0.060000 + 7 H7 36.7400 17.5440 33.8830 H 1 ETH 0.060000 + 8 H8 36.4770 18.7350 32.5470 H 1 ETH 0.060000 + 9 C8 29.0900 26.1850 32.0230 C 2 ETH -0.180000 + 10 C9 27.9240 27.0340 31.5460 C 2 ETH -0.180000 + 11 H10 30.0320 26.7690 31.9580 H 2 ETH 0.060000 + 12 H11 28.9240 25.8760 33.0760 H 2 ETH 0.060000 + 13 H12 29.1790 25.2790 31.3870 H 2 ETH 0.060000 + 14 H13 28.0890 27.3430 30.4920 H 2 ETH 0.060000 + 15 H14 26.9810 26.4500 31.6110 H 2 ETH 0.060000 + 16 H15 27.8340 27.9410 32.1810 H 2 ETH 0.060000 @BOND 1 1 2 1 2 1 3 1