Skip to content

mol2 writer #869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions gmso/formats/mol2.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,54 @@
def _parse_molecule(top, section, verbose):
"""Parse molecule information from the mol2 file."""
top.label = str(section[0].strip())


def _write_site_info(site, f, index=1):
"""Write site information to ATOM section."""
# TODO: Create rules to make sure nothing is too long, so that it cuts off.
lineList = [

Check warning on line 203 in gmso/formats/mol2.py

View check run for this annotation

Codecov / codecov/patch

gmso/formats/mol2.py#L203

Added line #L203 was not covered by tests
str(index),
site.element.symbol,
*map(str, site.position.value),
site.atom_type.name if site.atom_type else site.name,
str(site.molecule.number),
site.molecule.name,
str(site.charge) if site.charge else "0.00",
]
formattedStr = "\t".join(lineList) + "\n"
f.writelines(formattedStr)
index += 1

Check warning on line 214 in gmso/formats/mol2.py

View check run for this annotation

Codecov / codecov/patch

gmso/formats/mol2.py#L212-L214

Added lines #L212 - L214 were not covered by tests
# ATOM top.sites
# @<TRIPOS>ATOM
# 1 C -0.7600 1.1691 -0.0005 C.ar 1 BENZENE 0.000


def _write_bond_info(top, bond, f):
"""writes the bonds in a topology with assigned atom number."""
# need to add bond type info as well
atom_id = {site: idx + 1 for idx, site in enumerate(top.sites)}

Check warning on line 223 in gmso/formats/mol2.py

View check run for this annotation

Codecov / codecov/patch

gmso/formats/mol2.py#L223

Added line #L223 was not covered by tests

bond_list = []

Check warning on line 225 in gmso/formats/mol2.py

View check run for this annotation

Codecov / codecov/patch

gmso/formats/mol2.py#L225

Added line #L225 was not covered by tests

for bond in top.bonds:
idx1 = atom_id[bond.connection_members[0]]
idx2 = atom_id[bond.connection_members[1]]

Check warning on line 229 in gmso/formats/mol2.py

View check run for this annotation

Codecov / codecov/patch

gmso/formats/mol2.py#L227-L229

Added lines #L227 - L229 were not covered by tests

bond_list.append((min(idx1, idx2), max(idx1, idx2)))

Check warning on line 231 in gmso/formats/mol2.py

View check run for this annotation

Codecov / codecov/patch

gmso/formats/mol2.py#L231

Added line #L231 was not covered by tests

bond_info_str = "\n".join(f"{idx1} {idx2} un " for idx1, idx2 in bond_list)

Check warning on line 233 in gmso/formats/mol2.py

View check run for this annotation

Codecov / codecov/patch

gmso/formats/mol2.py#L233

Added line #L233 was not covered by tests
# un stands for unkown because bond type (order) is implicit in gms

return bond_info_str

Check warning on line 236 in gmso/formats/mol2.py

View check run for this annotation

Codecov / codecov/patch

gmso/formats/mol2.py#L236

Added line #L236 was not covered by tests


def _write_molecule_info(top, f):
name = top.name
num_atoms = top.n_sites
num_bonds = top.n_bonds

Check warning on line 242 in gmso/formats/mol2.py

View check run for this annotation

Codecov / codecov/patch

gmso/formats/mol2.py#L240-L242

Added lines #L240 - L242 were not covered by tests

return f"{name}\n{num_atoms} {num_bonds}"

Check warning on line 244 in gmso/formats/mol2.py

View check run for this annotation

Codecov / codecov/patch

gmso/formats/mol2.py#L244

Added line #L244 was not covered by tests


def _write_box_info(box, f):
pass

Check warning on line 248 in gmso/formats/mol2.py

View check run for this annotation

Codecov / codecov/patch

gmso/formats/mol2.py#L248

Added line #L248 was not covered by tests
Loading