Skip to content

Commit

Permalink
have charge balancing for itps but raise error when bond length is mi…
Browse files Browse the repository at this point in the history
…ssing
  • Loading branch information
fgrunewald committed Jan 24, 2024
1 parent 8f80a99 commit 08021c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 4 additions & 0 deletions polyply/src/charges.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ def _get_bonds(block, topology=None):
elif batoms[::-1] in topology.types['bonds']:
params = topology.types['bonds'][batoms[::-1]][0][0][1]
bonds[(nodes_to_count[idx], nodes_to_count[jdx])] = float(params)

Check warning on line 95 in polyply/src/charges.py

View check run for this annotation

Codecov / codecov/patch

polyply/src/charges.py#L94-L95

Added lines #L94 - L95 were not covered by tests
else:
msg = ("Cannot find bond lengths. If your force field uses bondtypes lile"

Check warning on line 97 in polyply/src/charges.py

View check run for this annotation

Codecov / codecov/patch

polyply/src/charges.py#L97

Added line #L97 was not covered by tests
"Charmm you need to provide a topology file.")
raise ValueError(msg)

Check warning on line 99 in polyply/src/charges.py

View check run for this annotation

Codecov / codecov/patch

polyply/src/charges.py#L99

Added line #L99 was not covered by tests
return bonds

def balance_charges(block, charge=0, tol=10**-5, decimals=5, topology=None):
Expand Down
11 changes: 5 additions & 6 deletions polyply/src/itp_to_ff.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def itp_to_ff(itppath, fragment_smiles, resnames, term_prefix, outpath, charges=
mol = top.molecules[0].molecule
# read itp file
if itppath.suffix == ".itp":
top = None
with open(itppath, "r") as _file:
lines = _file.readlines()
force_field = ForceField("tmp")
Expand All @@ -63,12 +64,10 @@ def itp_to_ff(itppath, fragment_smiles, resnames, term_prefix, outpath, charges=
new_block.nrexcl = mol.nrexcl
force_field.blocks[name] = new_block
set_charges(new_block, res_graph, name)
if itppath.suffix == ".top":
base_resname = name.split(term_prefix)[0].split('_')[0]
print(base_resname)
balance_charges(new_block,
topology=top,
charge=crg_dict[base_resname])
base_resname = name.split(term_prefix)[0].split('_')[0]
balance_charges(new_block,
topology=top,
charge=crg_dict[base_resname])

force_field.links = extract_links(mol)

Expand Down

0 comments on commit 08021c2

Please sign in to comment.