Skip to content

Commit

Permalink
Merge pull request #353 from brunostega/main
Browse files Browse the repository at this point in the history
Account for single atom topologies
  • Loading branch information
carlocamilloni authored Feb 26, 2024
2 parents c5add02 + 02e49fe commit d2b2409
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
2 changes: 2 additions & 0 deletions src/multiego/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,8 @@ def generate_14_data(meGO_ensemble):
pairs14 = pd.DataFrame()
exclusion_bonds14 = pd.DataFrame()
for molecule, bond_pair in meGO_ensemble["bond_pairs"].items():
if not bond_pair:
continue
reduced_topology = (
meGO_ensemble["topology_dataframe"]
.loc[meGO_ensemble["topology_dataframe"]["molecule_name"] == molecule][
Expand Down
52 changes: 31 additions & 21 deletions src/multiego/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ def get_bonds(topology):

bonds_data.append({"ai": ai, "aj": aj, "funct": funct, "req": req, "k": k})

bonds_dataframe = pd.DataFrame(bonds_data)
if bonds_data:
bonds_dataframe = pd.DataFrame(bonds_data)
# Conversion from KCal/mol/A^2 to KJ/mol/nm^2 and from Amber to Gromos
bonds_dataframe["req"] = bonds_dataframe["req"] / 10.0
bonds_dataframe["k"] = bonds_dataframe["k"] * 4.184 * 100 * 2
bonds_dataframe["k"] = bonds_dataframe["k"].map(lambda x: "{:.6e}".format(x))
else:
bonds_dataframe = pd.DataFrame(columns=["ai", "aj", "funct", "req", "k"])

# Conversion from KCal/mol/A^2 to KJ/mol/nm^2 and from Amber to Gromos
bonds_dataframe["req"] = bonds_dataframe["req"] / 10.0
bonds_dataframe["k"] = bonds_dataframe["k"] * 4.184 * 100 * 2
bonds_dataframe["k"] = bonds_dataframe["k"].map(lambda x: "{:.6e}".format(x))
return bonds_dataframe


Expand Down Expand Up @@ -104,15 +107,17 @@ def get_angles(topology):
# Append the angle data to the angles_data list as a dictionary
angles_data.append({"ai": ai, "aj": aj, "ak": ak, "funct": funct, "theteq": theteq, "k": k})

# Create a pandas DataFrame from the angles_data list
angles_dataframe = pd.DataFrame(angles_data)
if angles_data:
# Create a pandas DataFrame from the angles_data list
angles_dataframe = pd.DataFrame(angles_data)

# Convert k values from kcal/(mol*rad^2) to kJ/(mol*rad^2)
angles_dataframe["k"] = angles_dataframe["k"] * 4.184 * 2

# Format k values in scientific notation with 6 decimal places
angles_dataframe["k"] = angles_dataframe["k"].map(lambda x: "{:.6e}".format(x))
# Convert k values from kcal/(mol*rad^2) to kJ/(mol*rad^2)
angles_dataframe["k"] = angles_dataframe["k"] * 4.184 * 2

# Format k values in scientific notation with 6 decimal places
angles_dataframe["k"] = angles_dataframe["k"].map(lambda x: "{:.6e}".format(x))
else:
angles_dataframe = pd.DataFrame(columns=["ai", "aj", "ak", "funct", "theteq", "k"])
# Return the DataFrame containing angle data
return angles_dataframe

Expand Down Expand Up @@ -170,12 +175,14 @@ def get_dihedrals(topology):
dihedrals_data.append(
{"ai": ai, "aj": aj, "ak": ak, "al": al, "funct": funct, "phase": phase, "phi_k": phi_k, "per": per}
)
if dihedrals_data:
# Create a pandas DataFrame from the dihedrals_data list
dihedrals_dataframe = pd.DataFrame(dihedrals_data)

# Create a pandas DataFrame from the dihedrals_data list
dihedrals_dataframe = pd.DataFrame(dihedrals_data)

# Convert k values from kcal/(mol*rad^2) to kJ/(mol*rad^2)
dihedrals_dataframe["phi_k"] = dihedrals_dataframe["phi_k"] * 4.184
# Convert k values from kcal/(mol*rad^2) to kJ/(mol*rad^2)
dihedrals_dataframe["phi_k"] = dihedrals_dataframe["phi_k"] * 4.184
else:
dihedrals_dataframe = pd.DataFrame(columns=["ai", "aj", "ak", "al", "funct", "phase", "phi_k", "per"])

# Return the DataFrame containing dihedral data
return dihedrals_dataframe
Expand Down Expand Up @@ -220,11 +227,14 @@ def get_impropers(topology):
# Append the improper data to the impropers_data list as a dictionary
impropers_data.append({"ai": ai, "aj": aj, "ak": ak, "al": al, "funct": funct, "psi_eq": psi_eq, "psi_k": psi_k})

# Create a pandas DataFrame from the impropers_data list
impropers_dataframe = pd.DataFrame(impropers_data)
if impropers_data:
# Create a pandas DataFrame from the impropers_data list
impropers_dataframe = pd.DataFrame(impropers_data)

# Convert k values from kcal/(mol*rad^2) to kJ/(mol*rad^2)
impropers_dataframe["psi_k"] = impropers_dataframe["psi_k"] * 4.184 * 2
# Convert k values from kcal/(mol*rad^2) to kJ/(mol*rad^2)
impropers_dataframe["psi_k"] = impropers_dataframe["psi_k"] * 4.184 * 2
else:
impropers_dataframe = pd.DataFrame(columns=["ai", "aj", "ak", "al", "funct", "psi_eq", "psi_k"])

# Return the DataFrame containing improper data
return impropers_dataframe
Expand Down

0 comments on commit d2b2409

Please sign in to comment.