示例#1
0
def test_build_terachem_constraint_string():
    """
    Test build_geometric_constraint_string() function

    Notes
    -----
    Atom indices in constraits_string is 1-indexed
    Atom indices in dihedral_idxs is 0-indexed
    """
    constraints_dict = {
        'freeze': [{
            'type': 'xyz',
            'indices': [0, 1, 2, 5, 6],
        }, {
            'type': 'distance',
            'indices': [0, 4],
        }],
        'set': [
            {
                'type': 'distance',
                'indices': [0, 3],
                'value': 1.0,
            },
            {
                'type': 'angle',
                'indices': [1, 0, 3],
                'value': 30.0,
            },
            {
                'type': 'dihedral',
                'indices': [0, 1, 2, 3],
                'value': 60.0,
            },
        ]
    }
    constraints_string = build_terachem_constraint_string(constraints_dict)
    # validate the constraints string
    assert constraints_string.strip() == '\n'.join([
        '$constraint_freeze', 'xyz 1-3,6-7', 'bond 1_5', '$end\n',
        '$constraint_set', 'bond 1.0 1_4', 'angle 30.0 2_1_4',
        'dihedral 60.0 1_2_3_4', '$end'
    ])
    # test with dihedral_idx_values
    dihedral_idx_values = [(1, 2, 3, 4, 90.0), (2, 3, 4, 5, 120.0)]
    constraints_string2 = build_terachem_constraint_string(
        constraints_dict, dihedral_idx_values=dihedral_idx_values)
    assert constraints_string2.strip() == '\n'.join([
        '$constraint_freeze', 'xyz 1-3,6-7', 'bond 1_5', '$end\n',
        '$constraint_set', 'bond 1.0 1_4', 'angle 30.0 2_1_4',
        'dihedral 60.0 1_2_3_4', 'dihedral 90.0 2_3_4_5',
        'dihedral 120.0 3_4_5_6', '$end'
    ])
示例#2
0
 def optimize_native(self):
     """
     Run the constrained optimization.
     1. write a optimization job input file.
     2. run the job
     """
     assert self.temp_type == 'optimize', "To use native optimization, the input file be an opt job"
     if self.extra_constraints is None:
         self.constraintsStr = '\n$constraint_set\n'
         for d1, d2, d3, d4, v in self.dihedral_idx_values:
             # TeraChem use atom index starting from 1
             self.constraintsStr += f"dihedral {float(v)} {d1 + 1}_{d2 + 1}_{d3 + 1}_{d4 + 1}\n"
         self.constraintsStr += '$end\n'
     else:
         self.constraintsStr = build_terachem_constraint_string(
             self.extra_constraints, self.dihedral_idx_values)
     # write input file
     self.write_input()
     # run the job
     self.run('terachem run.in > run.out',
              input_files=['run.in', self.tera_geo_file],
              output_files=['run.out', 'scr'])