Skip to content

Commit

Permalink
Merge pull request #81 from bc118/fix_atom_numbering
Browse files Browse the repository at this point in the history
fixed annoyance in AA mol2 reader
  • Loading branch information
bc118 authored Nov 17, 2023
2 parents 5eb8f38 + 9a59c9f commit 49d946b
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 27 deletions.
62 changes: 51 additions & 11 deletions mosdef_gomc/formats/gmso_charmm_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,34 +471,60 @@ 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)."
)
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"
Expand All @@ -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)
)
Expand Down Expand Up @@ -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"
Expand Down
32 changes: 16 additions & 16 deletions mosdef_gomc/utils/files/2_ethane.mol2
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ USER_CHARGES
Energy = 0

@<TRIPOS>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
@<TRIPOS>BOND
1 1 2 1
2 1 3 1
Expand Down

0 comments on commit 49d946b

Please sign in to comment.