Skip to content

Commit

Permalink
Modified test_writer
Browse files Browse the repository at this point in the history
  • Loading branch information
laumalo committed Nov 2, 2020
1 parent 4429912 commit d9c6879
Showing 1 changed file with 48 additions and 15 deletions.
63 changes: 48 additions & 15 deletions offpele/tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,54 @@ def test_writer(self):

LIGAND_PATH = 'ligands/BNZ.pdb'
FORCEFIELD_NAME = 'openff_unconstrained-1.1.1.offxml'
TEMPLATE_EXAMPLE = 'ghfdh'

ligand_path = get_data_file_path(LIGAND_PATH)
molecule = Molecule(ligand_path)
molecule.parameterize(FORCEFIELD_NAME)
impact = Impact(molecule)
impact.write('molz')

with open(TEMPLATE_EXAMPLE, 'r') as f1:
contentA = set(f1)
with open('molz', 'r') as f2:
contentB = set(f2)
assert contentA == contentB


TEMPLATE_METZ = '/home/lauramalo/repos/offpele/offpele/tests/reference_templates/metz'

This comment has been minimized.

Copy link
@martimunicoy

martimunicoy Nov 2, 2020

Owner

Remember to use relative paths as we want the code to run in everyone's computer. So, move reference templates to offpele/data/tests/ and then get them with:

from offpele.utils import get_data_file_path
template_metz = get_data_file_path('tests/metz')
TEMPLATE_MATZ = '/home/lauramalo/repos/offpele/offpele/tests/reference_templates/malz'
TEMPLATE_ETLZ = '/home/lauramalo/repos/offpele/offpele/tests/reference_templates/etlz'

# Generates the tempalte for methane
pdb_path = get_data_file_path('ligands/methane.pdb')
m = Molecule(pdb_path)
m.parameterize('openff_unconstrained-1.2.1.offxml')
impact = Impact(m)
impact.write('metz')

# Compare the reference template and the generated template
with open(TEMPLATE_METZ, 'r') as f1:
dataA = f1.readlines()[3:]
with open('metz', 'r') as f2:
dataB = f2.readlines()[3:]
assert dataA == dataB

# Generates the template for malonate
pdb_path = get_data_file_path('ligands/malonate.pdb')
m = Molecule(pdb_path)
m.parameterize('openff_unconstrained-1.2.1.offxml')
impact = Impact(m)
impact.write('malz')

# Compare the reference template and the generated template
with open(TEMPLATE_MATZ, 'r') as f1:
dataA = f1.readlines()[3:]
with open('malz', 'r') as f2:
dataB = f2.readlines()[3:]
assert dataA == dataB

# Generates the template for ethylene
pdb_path = get_data_file_path('ligands/ethylene.pdb')
m = Molecule(pdb_path, tag='ETL') # Note that in this case we are assigning a tag to the molecule which will be used in the Impact template
m.parameterize('openff_unconstrained-1.2.1.offxml')
impact = Impact(m)
impact.write('etlz')

# Compare the reference template and the generated template
with open(TEMPLATE_ETLZ, 'r') as f1:
dataA = f1.readlines()[3:]
with open('etlz', 'r') as f2:
dataB = f2.readlines()[3:]
assert dataA == dataB

This comment has been minimized.

Copy link
@martimunicoy

martimunicoy Nov 2, 2020

Owner

Maybe comparing line by line has more sense and it would be easier to detect any differences between files (thinking on debugging). Therefore, I would change these global asserts by something like:

linesA = dataA.split('\n')
linesB = dataB.split('\n)
assert len(linesA) == len(linesB), 'Number of lines do not match'
for i, (lineA, lineB) in enumerate(zip(linesA, linesB)):
    assert lineA == lineB, 'Found different lines at line {}:' + lineA + ' - ' + lineB






Expand Down

0 comments on commit d9c6879

Please sign in to comment.