({{, (RefLink[MoleculeModify, paclet:ref/MoleculeModify])[mol,"mod"]
gives a molecule or list of molecules derived from the molecule mol by applying the modification "mod".}, {, (RefLink[MoleculeModify, paclet:ref/MoleculeModify])[mol,{"mod",specs}]
gives a molecule or list of molecules derived from the molecule mol by applying the modification "mod" with additional specifications specs.}, {, (RefLink[MoleculeModify, paclet:ref/MoleculeModify])["mod"]
represents an operator form of (RefLink[MoleculeModify, paclet:ref/MoleculeModify]) that can be applied to a molecule.}})

OpenersNotesSection(Spacer1)Details and Options

The following types of modification are supported:

(RefLink[MoleculeModify, paclet:ref/MoleculeModify])["mod",specs][mol] is equivalent to (RefLink[MoleculeModify, paclet:ref/MoleculeModify])[mol,"mod",specs].

(RefLink[MoleculeModify, paclet:ref/MoleculeModify])[mol,{"AddAtom", "sym"}] will add an atom with the given atomic symbol  (e.g. "C", "Cl").

For "AddAtom", spec should be an atom or list of atoms in one of the following forms:

"AddAtom" will add a disconnected atom, with no bonds to the rest of the molecule.

For "AddBond", spec should be a bond or list of bonds in one of the following forms:

For "DeleteAtom", spec should be an atom index or a list of atom indices.

For "DeleteBond", spec should be a (RefLink[Bond, paclet:ref/Bond]), a list of two bonded atom indices or a list of bonds.

For "EnergyMinimizeAtomCoordinates", it is possible to add a set of geometric constraints corresponding to additional terms in the MMFF force field. The constraints can be of the following forms:

"RenumberAtoms" takes a permutation of the atom indices {1,2,…,n}, where n is the number of atoms as returned by (RefLink[AtomCount, paclet:ref/AtomCount]).

In "ReplaceAtom", spec should be a rule id->atom from an atom index to a new atom or a list of such rules.

OpenersPrimaryExamplesSection(Spacer1)Examples  (38)

OpenersExampleSection0(Spacer1)Basic Examples  (5)

Add an atom to a molecule:

m = Molecule["propane"]

MoleculeModify[m,{"AddAtom",Atom["C"]}]

Add a bond to turn hexane into cyclohexane:

m=Molecule["hexane"]

MoleculeModify[m,{"AddBond",Bond[{1,6},"Single"]}]

Delete a bond to convert cyclohexane to hexane:

m=Molecule["cyclohexane"]

MoleculeModify[m,{"DeleteBond",Bond[{4,3},"Single"]}]

"ReplaceSubstructure":

m = Molecule@"trinitrotoluene"

MoleculeModify[m,{"ReplaceSubstructure",MoleculePattern["[#7](~[#8])~[#8]"]->"C"}]

MoleculeModify[m,{"ReplaceSubstructure",MoleculePattern[{"N","O","O"},{Bond[{1,2}],Bond[{1,3}]}]->"C"}]

"ReplaceSubstructureList":

m = Molecule@"trinitrotoluene"

MoleculeModify[m,{"ReplaceSubstructureList",MoleculePattern["[#7](~[#8])~[#8]"]->"C"}]

OpenersExampleSection1(Spacer1)Scope  (32)

OpenersExampleSubsection0(Spacer1)"AddAtom"  (1)

Add an atom to a molecule:

MoleculeModify[Molecule[],{"AddAtom","Fe"}]

Add a list of atoms:

MoleculeModify[Molecule[],{"AddAtom",{"Na+","Cl-"}}]

OpenersExampleSubsection1(Spacer1)"AddBond"  (1)

Add a bond to a molecule:

m=Molecule["cyclononane"]

Add a list of bonds to a molecule:

MoleculeModify[m,{"AddBond",{3,7}}]

OpenersExampleSubsection2(Spacer1)"AddHydrogens"  (1)

Convert implicit hydrogens to explicit:

m=Molecule[{"C","C"},{Bond[{1,2},"Single"]}]

MoleculeModify[m,"AddHydrogens"]

OpenersExampleSubsection3(Spacer1)"AssignStereochemistryFromCoordinates"  (1)

Use a molecule's 3D coordinates to infer stereochemistry:

m=ImportString[,"XYZ"]

m["StereochemistryElements"]

m2=MoleculeModify[m,"AssignStereochemistryFromCoordinates"]

m2["StereochemistryElements"]

OpenersExampleSubsection4(Spacer1)"ComputeAtomCoordinates"  (2)

Precompute the default coordinates and store them in the molecule under the (RefLink[AtomCoordinates, paclet:ref/AtomCoordinates]) option:

m=Molecule["FCCN1CCC(CC1)COc1ccc(cc1)C#N"]

Options@%

MoleculeModify[m,"ComputeAtomCoordinates"]

Options@%

Generate different conformations using the (RefLink[RandomSeeding, paclet:ref/RandomSeeding]) option:

{m1,m2,m3}=MoleculeModify[Molecule[],{"ComputeAtomCoordinates",RandomSeeding->#}]&/@{1,2,3};

MoleculePlot3D/@{m1,m2,m3}

OpenersExampleSubsection5(Spacer1)"DeleteAtom"  (2)

Convert hexanol to hexane using "DeleteAtom":

m=Molecule["2-hexanol"]

AtomList[m,"O","AtomIndex"]

MoleculeModify[m,{"DeleteAtom",%}]

When an atom is deleted, any hydrogens attached to it are also removed, and unfilled valences on heavy atoms are filled by hydrogens. Use (RefLink[ValenceErrorHandling, paclet:ref/ValenceErrorHandling])->(RefLink[False, paclet:ref/False]) to disable this behavior and leave unpaired electrons instead:

MoleculeModify[Molecule@"CCCP[C@@H]1C[C@@H]1C",{"DeleteAtom",4},ValenceErrorHandling->#]&/@{True,False}

MoleculePlot/@%

OpenersExampleSubsection6(Spacer1)"DeleteBond"  (2)

Delete an acyclic bond to create disconnected structures:

m=Molecule["diphenylamine"]

BondList[m,Bond[{"N","C"}]]

MoleculeModify[m,{"DeleteBond",First@%}]

MoleculePlot@%

Delete a ring bond:

m=Molecule[]

MoleculeModify[m,{"DeleteBond",{7,6}}]

OpenersExampleSubsection7(Spacer1)"EnergyMinimizeAtomCoordinates"  (1)

Import a structure from an (StringTypeLink["XYZ", paclet:ref/format/XYZ]) file and use the MMFF force field to minimize the energy:

m=Import["ExampleData/caffeine.xyz"]

MoleculeModify[m,"EnergyMinimizeAtomCoordinates"]

MoleculeValue[{m,%},"MMFFEnergy"]

OpenersExampleSubsection8(Spacer1)"Kekulize"  (1)

By default, aromatic molecules have delocalized "Aromatic" bond types:

m1=Molecule["benzene"]

BondList[m1,Bond[{"C","C"}]]

MoleculeModify[m1,"Kekulize"]

BondList[%,Bond[{"C","C"}]]

OpenersExampleSubsection9(Spacer1)"RemoveHydrogens"  (1)

Remove all the hydrogen atoms from a molecule:

mol=Molecule["cholesterol"]

mol["ElementCounts"]

mol2=MoleculeModify[mol,"RemoveHydrogens"]

mol2["ElementCounts"]

OpenersExampleSubsection10(Spacer1)"RemoveStereochemistry"  (1)

Remove explicit stereo information from a molecule, leaving the chirality undefined:

mol=Molecule["L-threonine"]

AtomList[mol,Atom["AtomChirality"->Except[None]],{"AtomIndex","AtomChirality"}]

mol2=MoleculeModify[mol,"RemoveStereochemistry"]

AtomList[mol2,Atom["AtomChirality"->Except[None]],{"AtomIndex","AtomChirality"}]

OpenersExampleSubsection11(Spacer1)"RenumberAtoms"  (1)

Remove explicit stereo information from a molecule, leaving the chirality undefined:

mol=Molecule["L-threonine"]

AtomList[mol,Atom["AtomChirality"->Except[None]],{"AtomIndex","AtomChirality"}]

mol2=MoleculeModify[mol,"RemoveStereochemistry"]

AtomList[mol2,Atom["AtomChirality"->Except[None]],{"AtomIndex","AtomChirality"}]

Change the ordering of atoms in a molecule:

m=Molecule["l-alanine"]

m2=MoleculeModify[m,{"RenumberAtoms",{13,12,11,10,9,8,7,6,5,4,3,2,1}}]

AtomList/@{m,m2}

MoleculeEquivalentQ[m,m2]

OpenersExampleSubsection12(Spacer1)"ReplaceAtom"  (1)

Replace specific atoms in a molecule with a different atom type; for example, convert acetic acid to thioacetic acid:

mol=Molecule["acetic acid"]

MoleculeModify[mol,{"ReplaceAtom",3->"S"}]

OpenersExampleSubsection13(Spacer1)"ReplaceSubstructure"  (1)

Replace the hydroxyl in the aliphatic D ring of estradiol with a carbonyl to make estrone:

estradiol=Molecule["C[C@]12CC[C@@H]3c4ccc(cc4CC[C@H]3[C@@H]1CC[C@@H]2O)O"]

estrone=MoleculeModify[estradiol,{"ReplaceSubstructure",MoleculePattern["CO"]->"C=O"}]

MoleculePlot/@{estradiol,estrone}

OpenersExampleSubsection14(Spacer1)"ReplaceSubstructureList"  (1)

Make each of the methyl ethers of glycerol:

mol=Molecule["glycerol"]

MoleculePlot/@MoleculeModify[mol,{"ReplaceSubstructureList",MoleculePattern["CO"]->"COC"}]

OpenersExampleSubsection15(Spacer1)"SetAromaticity"  (1)

Change localized single and double bonds to aromatic:

m=Molecule[];

BondList[m,Bond[{"C","C"}]]

m2=MoleculeModify[m,"SetAromaticity"]

BondList[m2,Bond[{"C","C"}]]

OpenersExampleSubsection16(Spacer1)"SetAtomChirality"  (1)

Convert D-glucose to D-mannose:

glucose=Molecule["D-glucose"]

AtomList[glucose,Atom["AtomChirality"->Except[None]],{"AtomIndex","AtomChirality"}]

mannose=MoleculeModify[glucose,{"SetAtomChirality",3->"S"}]

AtomList[mannose,Atom["AtomChirality"->Except[None]],{"AtomIndex","AtomChirality"}]

MoleculePlot3D[#,Style[3,Blue],ImageSize->Small]&/@{glucose,mannose}//Row

OpenersExampleSubsection17(Spacer1)"SetBondAngle"  (3)

Set the angle between three atoms:

m=Molecule["acetone"]

MoleculeModify[m,{"SetBondAngle",{1,2,4}->(QuantityPostfix[120, "°", degrees, "AngularDegrees"])}]

%[{"BondAngle",{1,2,4}}]

Set multiple bond angles:

MoleculeModify[m,{"SetBondAngle",{{1,2,4}->(Quantity[((3 π)/4), "rad", radians, "Radians"]),{1,2,3} ->(QuantityPostfix[106.`, "°", degrees, "AngularDegrees"])}}]

%[{"BondAngle",{{1,2,4},{1,2,3}}}]

Angles cannot be set for nonbonded atoms:

MoleculeModify[Molecule[],{"SetBondAngle",{9,6,7}->(QuantityPostfix[103, "°", degrees, "AngularDegrees"])}]

Bond angles in a ring cannot be set:

MoleculeModify[Molecule["benzene"],{"SetBondAngle",{1,2,3}->(QuantityPostfix[115, "°", degrees, "AngularDegrees"])}]

OpenersExampleSubsection18(Spacer1)"SetBondLength"  (1)

Set the distance between two bonded atoms:

mol=Molecule["chloroform"]

mol[{"BondLength",{2,5}}]

MoleculeModify[mol,{"SetBondLength",{2,5}->(Quantity[1.3, "Å", ångströms, "Angstroms"])}]

%[{"BondLength",{2,5}}]

MoleculeModify[mol,{"SetBondLength",{1,3}->(Quantity[1.3, "Å", ångströms, "Angstroms"])}]

OpenersExampleSubsection19(Spacer1)"SetBondStereo"  (1)

Convert natural E-cinnamaldehyde to the Z-form:

cinnE=Molecule["c1ccc(cc1)/C=C/C=O"]

cinnZ=MoleculeModify[cinnE,{"SetBondStereo",{7,8}->"Z"}]//MoleculeModify["ComputeAtomCoordinates"]

MoleculePlot3D[#,ImageSize->Small]&/@{cinnE,cinnZ}//Row

OpenersExampleSubsection20(Spacer1)"SetFormalCharge"  (1)

Make the zwitterion of phenylalanine:

m=MoleculeModify[Molecule["phenylalanine"],{"SetFormalCharge",{12->-1,1->+1}}]

MoleculePlot[m]

AtomList[m,Atom["FormalCharge"->Except[0]],{"AtomIndex","AtomicSymbol"}]

OpenersExampleSubsection21(Spacer1)"SetMassNumber"  (1)

Label the C-2 of mevalonolactone with ( ^13)C by setting the mass number to 13:

mvl=Molecule["(4R)-4-hydroxy-4-methyloxan-2-one"]

MoleculeModify[mvl,{"SetMassNumber",3->13}]

Use (RefLink[AtomList, paclet:ref/AtomList]) to find the labeled carbon:

AtomList[%,Atom["MassNumber"->13],"AtomIndex"]

Label the 5-pro-S hydrogen of mevalonolactone with deuterium by setting the mass number to 2:

labeledH=MoleculeModify[mvl,{"SetMassNumber",13->2}]

MoleculePlot3D[labeledH,Atom["MassNumber"->2]]

OpenersExampleSubsection22(Spacer1)"SetMetaInformation"  (1)

Add metadata to a molecule:

mol=MoleculeModify[Molecule[],{"SetMetaInformation",<|"C-number"->"123456-789"|>}]

mol["MetaInformation"]

Store experimental data in this property:

mol=MoleculeModify[mol,{"SetMetaInformation",<|"SpecificRotation"->{(QuantityPostfix[364, "°", degrees, "AngularDegrees"]),"@ 20°C, sat. CHCl3"}|>}]

mol["MetaInformation"]

Use an empty association to remove the metadata:

MoleculeModify[mol,{"SetMetaInformation",<||>}]

%["MetaInformation"]

OpenersExampleSubsection23(Spacer1)"SetTorsionAngle"  (1)

Set the geometry of a molecule to a desired conformation, for example, for an internal hydrogen bond:

mol=Molecule["OCCC=O"];

mol2=MoleculeModify[mol,{"SetTorsionAngle",{{6,1,2,3}->60,{1,2,3,4}->-60,{2,3,4,5}->60}}];

MoleculeValue[{mol,mol2},{"TorsionAngle",{{6,1,2,3},{1,2,3,4},{2,3,4,5}}}]

MoleculePlot3D/@{mol,mol2}

OpenersExampleSubsection24(Spacer1)"SetUnpairedElectronCount"  (1)

Create a hydroxy radical by modifying water:

MoleculeModify[Molecule[],{"SetUnpairedElectronCount",1->1}]

AtomList@%

OpenersExampleSubsection25(Spacer1)"TransformAtomCoordinates"  (2)

Create a copy of a molecule with the coordinates translated in space:

m1=Molecule["OC[C@@H](C(=O)O)NC(=O)[C@@H]1CCCN1"];

m2=MoleculeModify[m1, {"TransformAtomCoordinates",TranslationTransform[{(Quantity[10, "Å", ångströms, "Angstroms"]),(Quantity[10, "Å", ångströms, "Angstroms"]),(Quantity[10, "Å", ångströms, "Angstroms"])}]}]

MoleculePlot3D[#]&/@{m1,m2}

Show[%]

Create a molecule's enantiomer using (RefLink[ReflectionTransform, paclet:ref/ReflectionTransform]):

m=Molecule["(2S)-3-phenyl-2-[(2-phenylacetyl)amino]propanoic acid"]

AtomList[m,Atom["AtomChirality"->Except[None]],{"AtomIndex","AtomChirality"}]

m2=MoleculeModify[m,{"TransformAtomCoordinates",ReflectionTransform[{0,0,1}]}]

The molecule's stereo information needs updated to account for the new coordinates:

m3=MoleculeModify[m2,"AssignStereochemistryFromCoordinates"]

AtomList[m3,Atom["AtomChirality"->Except[None]],{"AtomIndex","AtomChirality"}]

MoleculeEquivalentQ[m,m3,"Enantiomers"]

OpenersExampleSection2(Spacer1)Neat Examples  (1)

Add distance constraints to the MMFF force field to find a conformation with a given distance between two atoms. First, create the base molecule:

m=Molecule["(3S,7S,11S,3'S,7'S,11'S)-1,1'-[(2R)-propane-1,2-diylbis(oxy)]bis(3,7,11,15-tetramethylhexadecane)"]

Find the two atoms that are farthest away in the standard configuration:

dmat=m["DistanceMatrix"]

FirstPosition[Normal[dmat],Max[dmat]]

The default conformation has these two atoms 32 ångströms apart:

dmat[[80,121]]

MoleculePlot3D[m,{Style[80,Blue],Style[121,Red]}]

Use "EnergyMinimizeAtomCoordinates" to find new conformations with specific separations for these atoms:

mod=MoleculeModify[m,{"EnergyMinimizeAtomCoordinates",{80,121}->#}]&/@{(Quantity[5, "Å", ångströms, "Angstroms"]),(Quantity[10, "Å", ångströms, "Angstroms"]),(Quantity[20, "Å", ångströms, "Angstroms"]),(Quantity[40, "Å", ångströms, "Angstroms"])}

Verify that the returned geometries match the requirement and get the force field energies:

MoleculeValue[mod,{{"InteratomicDistance",{80,121}},"MMFFEnergy"}]

MoleculePlot3D/@mod

m3=MoleculeModify[m,{"EnergyMinimizeAtomCoordinates",{72,117}->(Quantity[10, "Å", ångströms, "Angstroms"])}]

m3[{"InteratomicDistance",{72,117}}]

MoleculePlot3D[m3,{72,117}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Molecule, paclet:ref/Molecule])  ▪  (RefLink[Atom, paclet:ref/Atom])  ▪  (RefLink[Bond, paclet:ref/Bond])  ▪  (RefLink[AtomCoordinates, paclet:ref/AtomCoordinates])  ▪  (RefLink[StereochemistryElements, paclet:ref/StereochemistryElements])  ▪  (RefLink[ReplacePart, paclet:ref/ReplacePart])  ▪  (RefLink[ValenceErrorHandling, paclet:ref/ValenceErrorHandling])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Molecular Structure & Computation, paclet:guide/MolecularStructureAndComputation])}, {▪(RefLinkPlain[Physics & Chemistry: Data and Computation, paclet:guide/PhysicsAndChemistryDataAndComputation])}})}})