Skip to content

Document OFFXML string sources for ForceField - #2250

Merged
j-wags merged 3 commits into
openforcefield:mainfrom
AtharvaTilewale:fix/2021-forcefield-sources-docstring
Oct 27, 2026
Merged

j-wags merged 3 commits into
openforcefield:mainfrom
AtharvaTilewale:fix/2021-forcefield-sources-docstring

Conversation

@AtharvaTilewale

Copy link
Copy Markdown
Contributor

Documents that ForceField(), ForceField.parse_sources() and ForceField.parse_smirnoff_from_source() accept a string containing OFFXML content, in addition to file paths and file-like objects. As discussed in #2021, a string that does not resolve to a file name falls through to ParameterIOHandler.parse_string() and this has been de facto public API since the beginning, but all three sources/source docstrings described only files.

The parse_sources docstring also now says that a bare string is iterated character by character (iter(str) succeeds), so a single string source has to be wrapped in a list; ForceField(<string>) is unaffected because *sources already arrives as a tuple. This came out of checking each documented statement against the toolkit:

ForceField(<offxml string>)                              -> loads
ForceField().parse_sources([<offxml string>])            -> loads
ForceField().parse_sources(<offxml string>)              -> "Source '<' could not be read"
ForceField().parse_smirnoff_from_source(<offxml string>) -> {'SMIRNOFF': ...}
ForceField("openff-2.0.0.offxml")                        -> file-name lookup unchanged
ForceField("openff-2.0.0.offxml", <offxml string>)       -> mixed sources load

The __init__ entry is also reflowed into a bullet list, per the whitespace comment on the issue. ruff check passes (one rewrapped line was over the 119-character limit) and pytest openff/toolkit/_tests/test_forcefield.py -k "string or parse_sources or xml" gives 164 passed, 4 skipped. Docstring-only change, so no new tests. The release-history entry references this PR's number.

Fixes #2021

See our AI Policy. Please indicate whether LLMs or other AI-powered tools (beyond simple IDE use cases) were used in this contribution:

  • No
  • Yes

ForceField(), ForceField.parse_sources() and
ForceField.parse_smirnoff_from_source() accept a string containing
OFFXML content: a string that does not resolve to a file name is parsed
directly by ParameterIOHandler.parse_string(). The docstrings only
described file paths and file-like objects. Describe the string form in
all three places, and note that parse_sources iterates a bare string
character by character, so a single string source must be wrapped in a
list.

Fixes openforcefield#2021

Signed-off-by: Atharva Tilewale <[email protected]>
@j-wags j-wags self-assigned this Oct 26, 2026
@j-wags

j-wags commented Oct 27, 2026

Copy link
Copy Markdown
Member

Thanks for opening this @AtharvaTilewale - The CI failures are expected (we use a secret that isn't accessible from forks). I'll review this shortly!

@j-wags j-wags left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @AtharvaTilewale , this looks good to me. I'll push one change and merge!

Comment thread openff/toolkit/typing/engines/smirnoff/forcefield.py Outdated
@j-wags
j-wags merged commit 1ebb074 into openforcefield:main Oct 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ForceField sources allows strings but description doesn't seem mention it.

2 participants