def test_shorten_atomname(self, ethane): import foyer from mbuild.formats.cassandramcf import write_mcf typed_ethane = foyer.forcefields.load_OPLSAA().apply(ethane) typed_ethane[0].type = "C_very_very_very_extended" write_mcf( typed_ethane, "ethane-opls.mcf", angle_style="harmonic", dihedral_style="opls", ) mcf_data = [] with open("ethane-opls.mcf") as f: for line in f: mcf_data.append(line.strip().split()) for idx, line in enumerate(mcf_data): if len(line) > 1: if line[1] == "Atom_Info": atom_section_start = idx assert mcf_data[atom_section_start + 2][1] == "y_very_very_extended"
def write_mcfs(system): if not isinstance(system, mosdef_cassandra.System): raise TypeError('"system" must be of type ' "mosdef_cassandra.System") for species_count, species in enumerate(system.species_topologies): if not isinstance(species, parmed.Structure): raise TypeError('Your "system" object appears to have ' "been corrupted. Species {} is not a parmed" ".Structure object".format(species)) if len(species.dihedrals) > 0 and len(species.rb_torsions) > 0: raise ValueError( "Your species has both CHARMM style " "dihedrals and Ryckaert-Bellemans style dihedrals. " "Only a single dihedral style per species is " "currently supported") elif len(species.dihedrals) > 0: dihedral_style = "charmm" elif len(species.rb_torsions) > 0: dihedral_style = "opls" else: dihedral_style = "none" mcf_name = "species{}.mcf".format(species_count + 1) write_mcf( species, mcf_name, angle_style="harmonic", dihedral_style=dihedral_style, )
def test_infer_14_scaling_zero_eps(self): import mbuild import foyer from mbuild.formats.cassandramcf import write_mcf mol = mbuild.load("CO", smiles=True) mol_ff = foyer.forcefields.load_OPLSAA().apply(mol) with pytest.warns(UserWarning): write_mcf(mol_ff, "test.mcf", angle_style="harmonic", dihedral_style="opls")
def test_fused_rings(self): import foyer import mbuild from mbuild.formats.cassandramcf import write_mcf naph = mbuild.load("C1=CC=C2C=CC=CC2=C1", smiles=True) # Note the atomtyping is wrong -- doesn't matter for test though naph_ff = foyer.forcefields.load_OPLSAA().apply(naph) write_mcf(naph_ff, "naph.mcf", angle_style="harmonic", dihedral_style="opls") mcf_data = [] with open("naph.mcf") as f: for line in f: mcf_data.append(line.strip().split()) for idx, line in enumerate(mcf_data): if len(line) > 1: if line[1] == "Fragment_Info": frag_section_start = idx assert int(mcf_data[frag_section_start + 1][0]) == 1 assert int(mcf_data[frag_section_start + 2][1]) == 18 tmada = mbuild.load("C[C](C)(C)C12CC3CC(C1)CC(C3)C2", smiles=True) tmada_ff = foyer.forcefields.load_OPLSAA().apply(tmada) write_mcf(tmada_ff, "tmada.mcf", angle_style="harmonic", dihedral_style="opls") mcf_data = [] with open("tmada.mcf") as f: for line in f: mcf_data.append(line.strip().split()) for idx, line in enumerate(mcf_data): if len(line) > 1: if line[1] == "Fragment_Info": frag_section_start = idx assert int(mcf_data[frag_section_start + 1][0]) == 5 assert int(mcf_data[frag_section_start + 2][1]) == 26 assert int(mcf_data[frag_section_start + 3][1]) == 5 assert int(mcf_data[frag_section_start + 4][1]) == 5 assert int(mcf_data[frag_section_start + 5][1]) == 5 assert int(mcf_data[frag_section_start + 6][1]) == 5
def write_mcfs(system, angle_style="harmonic"): """Write a MCF file for a given mosdef_cassandra.System Parameters ---------- system : mosdef_cassandra.System System to simulate in Cassandra angle_style : str, default="harmonic" Angle style for the system, valid arguments: "harmonic", "fixed" """ if type(angle_style) == str: angle_style = [angle_style] * len(system.species_topologies) for astyle in angle_style: if astyle not in ["harmonic", "fixed"]: raise ValueError( 'Invalid "angle_style" {} given.'.format(angle_style) ) if not isinstance(system, mosdef_cassandra.System): raise TypeError('"system" must be of type ' "mosdef_cassandra.System") for species_count, species in enumerate(system.species_topologies): if not isinstance(species, parmed.Structure): raise TypeError( 'Your "system" object appears to have ' "been corrupted. Species {} is not a parmed" ".Structure object".format(species) ) if len(species.dihedrals) > 0 and len(species.rb_torsions) > 0: raise ValueError( "Your species has both CHARMM style " "dihedrals and Ryckaert-Bellemans style dihedrals. " "Only a single dihedral style per species is " "currently supported" ) elif len(species.dihedrals) > 0: dihedral_style = "charmm" elif len(species.rb_torsions) > 0: dihedral_style = "opls" else: dihedral_style = "none" mcf_name = "species{}.mcf".format(species_count + 1) write_mcf( species, mcf_name, angle_style=angle_style[species_count], dihedral_style=dihedral_style, )
def build_run_measure_cassandra(structure): py2, fraglib_setup, cassandra = detect_cassandra_binaries() workdir = os.getcwd() mcf_file = 'structure.mcf' xyz_file = 'structure.xyz' pdb_file = 'structure.pdb' with temporary_directory() as tmp_dir: with temporary_cd(tmp_dir): # Guess dihedral type...from contents of structure if len(structure.dihedrals) > 0: dihedral_style = 'charmm' else: dihedral_style = 'opls' write_mcf(structure, mcf_file, angle_style='harmonic', dihedral_style=dihedral_style) mb.load(structure).save(xyz_file) mb.load(structure).to_trajectory().save_pdb(pdb_file) inp_file, output = write_cassandra_inp() successful_fraglib = run_fraglib_setup(py2, fraglib_setup, cassandra, inp_file, mcf_file, pdb_file, workdir) if successful_fraglib: run_cassandra(cassandra, inp_file, workdir) energies = get_cassandra_energy(output + '.log') else: print( "Cassandra failed due to unsuccessful fragment generation") df = pd.DataFrame.from_dict(energies, orient='index') return df