def make_system(molecules, numbers, ff, box=None, virtual_sites=False, drudes=False): from shutil import which from mstools.wrapper import Packmol packmol_path = which("packmol") packmol = Packmol(packmol_path) # convert to nm - nargs gives a list if len(box) == 1: box = [b / 10 for b in box] * 3 else: box = [b / 10 for b in box] top = Topology(molecules) top.generate_angle_dihedral_improper() if virtual_sites: top.generate_virtual_sites(ff) if drudes: top.generate_drude_particles(ff) top.assign_charge_from_ff(ff) top.cell.set_box(box) top.scale_with_packmol(numbers, packmol) return System(top, ff)
if mol.has_position: logger.warning(f'{str(mol)} carries no bond. Guessing connectivity from FF') mol.guess_connectivity_from_ff(ff, angle_tolerance=15, pbc='xyz', cell=top.cell) else: logger.warning(f'{str(mol)} carries no bond. Make sure the topology is correct') if ff.is_polarizable: mol.generate_drude_particles(ff) if ff.has_virtual_site: mol.generate_virtual_sites(ff) mol.assign_mass_from_ff(ff) mol.assign_charge_from_ff(ff) if args.packmol: top.update_molecules(list(mol_count.keys())) top.scale_with_packmol(list(mol_count.values())) sys.exit(0) logger.info('Exporting ...') top.update_molecules(list(mol_count.keys()), list(mol_count.values())) if args.trj is None: logger.warning('Trajectory file not provided. ' 'Will use positions and cell from the topology') else: _positions_set = False if len(frame.positions) == top.n_atom: top.set_positions(frame.positions) _positions_set = True elif ff.is_polarizable or ff.has_virtual_site:
h_1 c_4 c_4h2 c_4h3 ''' typer = ZftTyper(io.StringIO(definition)) butane = Molecule.from_smiles('CCCC butane') typer.type_molecule(butane) # Load force field parameters from ZFP file ff = ForceField.open('alkane.zfp') # Initialize a topology with periodic boundary condition # For now, it contains only one butane molecule top = Topology([butane], cell=UnitCell([3, 3, 3])) # Assign atomic charges based on the charge parameters in the force field top.assign_charge_from_ff(ff) # Call Packmol to build a configuration containing 100 butane molecules packmol = Packmol(r'/path/of/packmol') top.scale_with_packmol([100], packmol=packmol) # Associate force field parameters to the topology # And then export input files for simulation engines system = System(top, ff) system.export_gromacs() system.export_lammps() system.export_charmm()