class Chem::Structure
- Chem::Structure
- Reference
- Object
Defined in:
chem/core/structure.crchem/register_format.cr
Constant Summary
-
MAX_CHAINS =
62
-
MIN_RING_ANGLE =
50
Constructors
- .build(*args, **options, &) : self
-
.from_chgcar(input : IO | Path | String) : self
Returns the structure encoded in input using the
Chem::VASP::Chgcar
file format. -
.from_cube(input : IO | Path | String) : self
Returns the structure encoded in input using the
Chem::Cube
file format. -
.from_gen(input : IO | Path | String, guess_bonds : Bool = false, guess_names : Bool = false) : self
Returns the structure encoded in input using the
Chem::Gen
file format. -
.from_jdftx(input : IO | Path | String, guess_bonds : Bool = false, guess_names : Bool = false) : self
Returns the structure encoded in input using the
Chem::JDFTx
file format. -
.from_locpot(input : IO | Path | String) : self
Returns the structure encoded in input using the
Chem::VASP::Locpot
file format. -
.from_mol(input : IO | Path | String) : self
Returns the structure encoded in input using the
Chem::Mol
file format. -
.from_mol2(input : IO | Path | String) : self
Returns the structure encoded in input using the
Chem::Mol2
file format. -
.from_pdb(input : IO | Path | String, alt_loc : Char | Nil = nil, chains : Enumerable(Char) | String | Nil = nil, guess_bonds : Bool = false, het : Bool = true) : self
Returns the structure encoded in input using the
Chem::PDB
file format. -
.from_poscar(input : IO | Path | String, guess_bonds : Bool = false, guess_names : Bool = false) : self
Returns the structure encoded in input using the
Chem::VASP::Poscar
file format. -
.from_psf(input : IO | Path | String) : self
Returns the structure encoded in input using the
Chem::PSF
file format. -
.from_sdf(input : IO | Path | String) : self
Returns the structure encoded in input using the
Chem::SDF
file format. -
.from_xyz(input : IO | Path | String, guess_bonds : Bool = false, guess_names : Bool = false) : self
Returns the structure encoded in input using the
Chem::XYZ
file format. - .new(source_file : Path | String | Nil = nil)
-
.read(input : IO | Path | String, format : Chem::Format | String) : self
Returns the structure encoded in the specified file using format.
-
.read(path : Path | String) : self
Returns the structure encoded in the specified file.
Class Method Summary
-
.guess_element(atom_name : String) : Element
Returns the element of an atom based on its name.
-
.guess_element?(atom_name : String) : Element | Nil
Returns the element of an atom based on its name if possible, else
nil
.
Instance Method Summary
- #[](chain_id : Char) : Chain
- #[]?(chain_id : Char) : Chain | Nil
-
#angles : Array::View(Angle)
Returns the angles in the topology.
-
#angles=(angles : Array(Chem::Angle))
Angles in the topology.
-
#apply_templates : Nil
Assign bonds, formal charges, and residue's type from known residue types.
- #atoms : AtomView
- #biases : Array(Chem::Bias)
-
#bonds : Array(Bond)
Returns the bonds between all atoms.
-
#cell : Spatial::Parallelepiped
Returns the unit cell.
- #cell=(cell : Spatial::Parallelepiped | Nil)
- #cell? : Spatial::Parallelepiped | Nil | Nil
- #chains : ChainView
- #clear : self
-
#clone : self
Returns a deep copy of
self
, that is, every chain/residue/atom is copied. - #delete(ch : Chain) : Chain | Nil
- #dig(id : Char) : Chain
- #dig(id : Char, *subindexes)
- #dig?(id : Char) : Chain | Nil
- #dig?(id : Char, *subindexes)
-
#dihedrals : Array::View(Dihedral)
Returns the dihedral angles in the topology.
-
#dihedrals=(dihedrals : Array(Chem::Dihedral))
Dihedral angles in the topology.
- #experiment : Structure::Experiment | Nil
- #experiment=(experiment : Structure::Experiment | Nil)
-
#extract(copy_properties : Bool = true, & : Atom -> Bool) : self
Returns a new structure containing the selected atoms by the given block.
-
#formal_charge : Int32
TODO implement compound accessors in a global module
-
#guess_angles : Nil
Determines the angles based on connectivity.
-
#guess_bonds(perceive_order : Bool = true) : Nil
Determines the bonds from connectivity and geometry.
-
#guess_dihedrals : Nil
Determines the dihedral angles based on connectivity.
-
#guess_formal_charges : Nil
Sets the formal charges based on the existing bonds.
-
#guess_impropers : Nil
Determines the improper dihedral angles based on connectivity.
-
#guess_names(registry : Templates::Registry = Templates::Registry.default) : Nil
Detects and assigns topology names from known residue templates based on bond information.
-
#guess_unknown_residue_types : Nil
Determines the type of unknown residues based on their neighbors.
-
#impropers : Array::View(Improper)
Returns the improper dihedral angles in the topology.
-
#impropers=(impropers : Array(Chem::Improper))
Improper dihedral angles in the topology.
-
#inspect(io : IO) : Nil
Appends a String representation of this object which includes its class name, its object address and the values of all instance variables.
-
#metadata : Chem::Metadata
Hash-like container that stores the structure's properties as key (string)-value pairs.
- #periodic? : Bool
- #pos : Spatial::Positions3Proxy
-
#pos=(pos : Spatial::Positions3) : Spatial::Positions3
Sets the atom coordinates and cell.
-
#pos=(pos : Enumerable(Spatial::Vec3)) : Enumerable(Spatial::Vec3)
Sets the atom coordinates.
-
#renumber_residues_by(& : Residue -> _) : Nil
Renumber residues per chain based on the order by the output value of the block.
-
#renumber_residues_by_connectivity(split_chains : Bool = true) : Nil
Renumber chain and residues based on bond information.
-
#reset_connectivity : Nil
Deletes all bonds and resets formal charges to zero.
- #residues : ResidueView
- #source_file : Path | Nil
- #title : String
- #title=(title : String)
-
#to_gen(fractional : Bool = false) : String
Returns a string representation of the structure using the
Chem::Gen
file format. -
#to_gen(output : IO | Path | String, fractional : Bool = false) : Nil
Writes the structure to output using the
Chem::Gen
file format. -
#to_jdftx(fractional : Bool = false, wrap : Bool = false, single_file : Bool = true) : String
Returns a string representation of the structure using the
Chem::JDFTx
file format. -
#to_jdftx(output : IO | Path | String, fractional : Bool = false, wrap : Bool = false, single_file : Bool = true) : Nil
Writes the structure to output using the
Chem::JDFTx
file format. -
#to_mol(variant : Chem::Mol::Variant = :v2000) : String
Returns a string representation of the structure using the
Chem::Mol
file format. -
#to_mol(output : IO | Path | String, variant : Chem::Mol::Variant = :v2000) : Nil
Writes the structure to output using the
Chem::Mol
file format. -
#to_mol2(output : IO | Path | String) : Nil
Writes the structure to output using the
Chem::Mol2
file format. -
#to_mol2 : String
Returns a string representation of the structure using the
Chem::Mol2
file format. -
#to_pdb(bonds : Chem::PDB::Writer::BondOptions = Chem::PDB::Writer::BondOptions.flags(Het, Disulfide), renumber : Bool = true, ter_on_fragment : Bool = false) : String
Returns a string representation of the structure using the
Chem::PDB
file format. -
#to_pdb(output : IO | Path | String, bonds : Chem::PDB::Writer::BondOptions = Chem::PDB::Writer::BondOptions.flags(Het, Disulfide), renumber : Bool = true, ter_on_fragment : Bool = false) : Nil
Writes the structure to output using the
Chem::PDB
file format. -
#to_poscar(order : Array(Element) | Array(String) | Nil = nil, fractional : Bool = false, wrap : Bool = false) : String
Returns a string representation of the structure using the
Chem::VASP::Poscar
file format. -
#to_poscar(output : IO | Path | String, order : Array(Element) | Array(String) | Nil = nil, fractional : Bool = false, wrap : Bool = false) : Nil
Writes the structure to output using the
Chem::VASP::Poscar
file format. -
#to_pymol(output : IO | Path | String) : Nil
Writes the structure to output using the
Chem::PyMOL
file format. -
#to_pymol : String
Returns a string representation of the structure using the
Chem::PyMOL
file format. -
#to_s(io : IO)
Appends a short String representation of this object which includes its class name and its object address.
-
#to_sdf(variant : Chem::Mol::Variant = :v2000) : String
Returns a string representation of the structure using the
Chem::SDF
file format. -
#to_sdf(output : IO | Path | String, variant : Chem::Mol::Variant = :v2000) : Nil
Writes the structure to output using the
Chem::SDF
file format. -
#to_stride(output : IO | Path | String) : Nil
Writes the structure to output using the
Chem::Protein::Stride
file format. -
#to_stride : String
Returns a string representation of the structure using the
Chem::Protein::Stride
file format. -
#to_vmd(output : IO | Path | String) : Nil
Writes the structure to output using the
Chem::VMD
file format. -
#to_vmd : String
Returns a string representation of the structure using the
Chem::VMD
file format. -
#to_xyz(extended : Bool = false, fields : Array(String) = [] of String) : String
Returns a string representation of the structure using the
Chem::XYZ
file format. -
#to_xyz(output : IO | Path | String, extended : Bool = false, fields : Array(String) = [] of String) : Nil
Writes the structure to output using the
Chem::XYZ
file format. -
#write(output : IO | Path | String, format : Chem::Format | String) : Nil
Writes the structure to output using format.
-
#write(path : Path | String) : Nil
Writes the structure to the specified file.
Constructor Detail
Returns the structure encoded in input using the
Chem::VASP::Chgcar
file format. Arguments are forwarded to
Chem::VASP::Chgcar::Reader.open
.
Returns the structure encoded in input using the
Chem::Cube
file format. Arguments are forwarded to
Chem::Cube::Reader.open
.
Returns the structure encoded in input using the
Chem::Gen
file format. Arguments are forwarded to
Chem::Gen::Reader.open
.
Returns the structure encoded in input using the
Chem::JDFTx
file format. Arguments are forwarded to
Chem::JDFTx::Reader.open
.
Returns the structure encoded in input using the
Chem::VASP::Locpot
file format. Arguments are forwarded to
Chem::VASP::Locpot::Reader.open
.
Returns the structure encoded in input using the
Chem::Mol
file format. Arguments are forwarded to
Chem::Mol::Reader.open
.
Returns the structure encoded in input using the
Chem::Mol2
file format. Arguments are forwarded to
Chem::Mol2::Reader.open
.
If input contains multiple entries, this method returns
the first one only. Use Array#from_mol2
or
Chem::Mol2::Reader#each
to get multiple entries instead.
Returns the structure encoded in input using the
Chem::PDB
file format. Arguments are forwarded to
Chem::PDB::Reader.open
.
If input contains multiple entries, this method returns
the first one only. Use Array#from_pdb
or
Chem::PDB::Reader#each
to get multiple entries instead.
Returns the structure encoded in input using the
Chem::VASP::Poscar
file format. Arguments are forwarded to
Chem::VASP::Poscar::Reader.open
.
Returns the structure encoded in input using the
Chem::PSF
file format. Arguments are forwarded to
Chem::PSF::Reader.open
.
Returns the structure encoded in input using the
Chem::SDF
file format. Arguments are forwarded to
Chem::SDF::Reader.open
.
If input contains multiple entries, this method returns
the first one only. Use Array#from_sdf
or
Chem::SDF::Reader#each
to get multiple entries instead.
Returns the structure encoded in input using the
Chem::XYZ
file format. Arguments are forwarded to
Chem::XYZ::Reader.open
.
If input contains multiple entries, this method returns
the first one only. Use Array#from_xyz
or
Chem::XYZ::Reader#each
to get multiple entries instead.
Returns the structure encoded in the specified file
using format. Raises ArgumentError
if format has
required arguments or cannot read Chem::Structure
.
If input contains multiple entries, this method returns
the first one only. Use Array.read
or
Chem::FormatReader::MultiEntry#each
(reader can be
obtained via Chem::Format.reader
) to get multiple entries
instead.
The supported file formats are Chem::Cube
, Chem::Gen
, Chem::JDFTx
, Chem::Mol2
, Chem::Mol
, Chem::PDB
, Chem::PSF
, Chem::SDF
, Chem::VASP::Chgcar
, Chem::VASP::Locpot
, Chem::VASP::Poscar
, Chem::XYZ
. Use the
.from_*
methods to customize how the object is decoded in
the corresponding file format if possible.
Returns the structure encoded in the specified file.
The file format is chosen based on the filename (see
Chem::Format#from_filename
). Raises ArgumentError
if the
file format cannot be determined.
If the file contains multiple entries, this method returns
the first one only. Use Array.read
to get multiple entries
instead.
The supported file formats are the following:
Chem::Gen
(.gen)Chem::JDFTx
(.ionpos, .lattice)Chem::Mol
(.mol)Chem::Mol2
(.mol2)Chem::PDB
(.ent, .pdb)Chem::PSF
(.psf)Chem::SDF
(.sdf)Chem::XYZ
(.xyz)Chem::VASP::Poscar
(.poscar, POSCAR, CONTCAR)Chem::Cube
(.cube)Chem::VASP::Chgcar
(CHGCAR)Chem::VASP::Locpot
(LOCPOT)
Use the .from_*
methods to customize how the object is
decoded in the corresponding file format if possible.
Class Method Detail
Returns the element of an atom based on its name. Raises Error
if
the element could not be determined. Refer to .guess_element?
for
details.
TODO Move to Chem
namespace
Returns the element of an atom based on its name if possible, else
nil
.
This is a naive approach, where the first letter of atom_name is tested first to get the element, then the name with trailing digits stripped.
TODO Move to Chem
namespace
Instance Method Detail
Returns the angles in the topology. See Angle
for definition.
Angles in the topology. See Angle
for definition.
Assign bonds, formal charges, and residue's type from known residue types.
Returns the unit cell. Raises Spatial::NotPeriodicError
if cell
is nil
.
Returns a deep copy of self
, that is, every chain/residue/atom is copied.
Unlike array-like classes in the language, #dup
(shallow copy) is not possible.
structure = Structure.new "/path/to/file.pdb"
other = structure.clone
other == structure # => true
other.same?(structure) # => false
structure.dig('A', 23, "OG").partial_charge # => 0.0
other.dig('A', 23, "OG").partial_charge # => 0.0
structure.dig('A', 23, "OG").partial_charge = 0.635 # => 0.635
other.dig('A', 23, "OG").partial_charge # => 0.0
Returns the dihedral angles in the topology. See Dihedral
for
definition.
Dihedral angles in the topology. See Dihedral
for definition.
Returns a new structure containing the selected atoms by the given block.
Structure properties such as biases, unit cell, title, etc. are
copied only if copy_properties is true
.
Determines the angles based on connectivity. See Angle
for
definition.
NOTE It deletes existing angles.
Determines the bonds from connectivity and geometry.
Bonds are added when the pairwise distances are within the
corresponding covalent distances (see
PeriodicTable.covalent_distance
). Bonds are added until the atoms'
valences are fulfilled. If extraneous bonds are found (beyond the
maximum number of bonds, see Element#max_bonds
), the longest ones
will be removed.
Bonds to atoms that could potential be as cations (K, Na, etc.) are disfavored such that they won't be added if the neighbor is over-valence or the bond can be substituted by increasing the bond order of another bond of the neighbor (e.g., C-O + K is preferred over C-O-K since C-O can be converted to C=O).
Bond orders are assigned based on the following procedure. First,
atom hybridization is guessed from the geometry. Then, the bond
orders are determined such that both atoms must have the same
hybridization to assign a double (sp2) or triple (sp) bond. Bond
order is only changed if the bonded atoms have missing valence. If
multiple bonded atoms fulfill the requirements for increasing the
bond order, the atom with the most missing valence or that is
closest to the current atom is selected first. This procedure is
loosely based on OpenBabel's PerceiveBondOrders
function.
Determines the dihedral angles based on connectivity. See Dihedral
for definition.
NOTE It deletes existing dihedral angles.
Sets the formal charges based on the existing bonds.
For most cases, the formal charge is calculated as
Nele - Tele + V
where Nele is the number of valence electrons, Tele is the
number of electrons in the full valence shell, and V is the
effective valence, which is equivalent to the sum of the bond
orders. Tele is usually 8 following the octet rule, but there are
some exceptions (see Element#target_electrons
).
If an atom has no bonds, it is considered as a monoatomic ion, where
the formal charge is set according to the following rule: if the
valence electrons < 4 (cation, e.g., Na+, Mg2+), the formal charge
is equal to the number of valence electrons, else (anions, e.g.,
Cl-) it is equal to Nele - Tele
.
WARNING Elements that have no valence determined such as transition metals are ignored.
Determines the improper dihedral angles based on connectivity. See
Improper
for definition.
Improper dihedral angles are often used to constraint the planarity of certain functional groups of molecules in molecular mechanics simulations, and so not every possible improper dihedral angle is required. This method lists every possible improper dihedral angle following the formal definition, which will probably generate extraneous angles.
NOTE It deletes existing improper dihedral angles.
Detects and assigns topology names from known residue templates based on bond information.
The method creates chains and residues according to the detected fragments and residue matches. The procedure is as follows. First, atoms are split into fragments, where each fragment is scanned for matches to known residue templates. Then, fragments are divided into polymer (e.g., peptide) and non-polymer (e.g., water) fragments based on the number of residues per fragment. Non-polymer residues are grouped together by their type (i.e., ion, solvent, etc.). Finally, every polymer fragment and group of non-polymer fragments are assigned to a unique chain and residues are created for each match.
NOTE Fragments are assigned to a unique chain unless the chain limit (62) is reached, otherwise all residues are assigned to the same chain.
WARNING Existing chains and residues are invalid after calling this method so do not cache them.
Determines the type of unknown residues based on their neighbors.
Returns the improper dihedral angles in the topology. See Improper
for definition.
Improper dihedral angles in the topology. See Improper
for
definition.
Appends a String representation of this object which includes its class name, its object address and the values of all instance variables.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).inspect # => #<Person:0x10fd31f20 @name="John", @age=32>
Hash-like container that stores the structure's properties as key
(string)-value pairs. A property's value can be any of the
primitive types (string, integer, float, or bool), and so it's
internally stored as Metadata::Any
. Use the cast methods
(#as_*
) to convert to the desired type.
structure.metadata["foo"] = 123
structure.metadata["foo"] # => Metadata::Any(123)
structure.metadata["foo"].as_i # => 123
structure.metadata["foo"].as_f # => 123.0
structure.metadata["foo"].as_s # raises TypeCastError
Sets the atom coordinates and cell.
Sets the atom coordinates.
Renumber residues per chain based on the order by the output value of the block.
NOTE This won't change the order of the existing chains.
Renumber chain and residues based on bond information.
Residue fragments are assigned to unique chains unless
split_chains is false
, which keeps existing chains intact.
Residue ordering is computed based on the link bond if available.
NOTE existing chains are reused to re-arrange the residues among them, so avoid caching them before calling this.
Returns a string representation of the structure using
the Chem::Gen
file format. Arguments are forwarded to
Chem::Gen::Writer.open
.
Writes the structure to output using the Chem::Gen
file format. Arguments are forwarded to Chem::Gen::Writer.open
.
Returns a string representation of the structure using
the Chem::JDFTx
file format. Arguments are forwarded to
Chem::JDFTx::Writer.open
.
Writes the structure to output using the Chem::JDFTx
file format. Arguments are forwarded to Chem::JDFTx::Writer.open
.
Returns a string representation of the structure using
the Chem::Mol
file format. Arguments are forwarded to
Chem::Mol::Writer.open
.
Writes the structure to output using the Chem::Mol
file format. Arguments are forwarded to Chem::Mol::Writer.open
.
Writes the structure to output using the Chem::Mol2
file format. Arguments are forwarded to Chem::Mol2::Writer.open
.
Returns a string representation of the structure using
the Chem::Mol2
file format. Arguments are forwarded to
Chem::Mol2::Writer.open
.
Returns a string representation of the structure using
the Chem::PDB
file format. Arguments are forwarded to
Chem::PDB::Writer.open
.
Writes the structure to output using the Chem::PDB
file format. Arguments are forwarded to Chem::PDB::Writer.open
.
Returns a string representation of the structure using
the Chem::VASP::Poscar
file format. Arguments are forwarded to
Chem::VASP::Poscar::Writer.open
.
Writes the structure to output using the Chem::VASP::Poscar
file format. Arguments are forwarded to Chem::VASP::Poscar::Writer.open
.
Writes the structure to output using the Chem::PyMOL
file format. Arguments are forwarded to Chem::PyMOL::Writer.open
.
Returns a string representation of the structure using
the Chem::PyMOL
file format. Arguments are forwarded to
Chem::PyMOL::Writer.open
.
Appends a short String representation of this object which includes its class name and its object address.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).to_s # => #<Person:0x10a199f20>
Returns a string representation of the structure using
the Chem::SDF
file format. Arguments are forwarded to
Chem::SDF::Writer.open
.
Writes the structure to output using the Chem::SDF
file format. Arguments are forwarded to Chem::SDF::Writer.open
.
Writes the structure to output using the Chem::Protein::Stride
file format. Arguments are forwarded to Chem::Protein::Stride::Writer.open
.
Returns a string representation of the structure using
the Chem::Protein::Stride
file format. Arguments are forwarded to
Chem::Protein::Stride::Writer.open
.
Writes the structure to output using the Chem::VMD
file format. Arguments are forwarded to Chem::VMD::Writer.open
.
Returns a string representation of the structure using
the Chem::VMD
file format. Arguments are forwarded to
Chem::VMD::Writer.open
.
Returns a string representation of the structure using
the Chem::XYZ
file format. Arguments are forwarded to
Chem::XYZ::Writer.open
.
Writes the structure to output using the Chem::XYZ
file format. Arguments are forwarded to Chem::XYZ::Writer.open
.
Writes the structure to output using format. Raises
ArgumentError
if format has required arguments or cannot
write Chem::Structure
.
The supported file formats are Chem::Gen
, Chem::JDFTx
, Chem::Mol2
, Chem::Mol
, Chem::PDB
, Chem::Protein::Stride
, Chem::PyMOL
, Chem::SDF
, Chem::VASP::Poscar
, Chem::VMD
, Chem::XYZ
. Use the
#to_*
methods to customize how the object is written in the
corresponding file format if possible.
Writes the structure to the specified file. The file
format is chosen based on the filename (see
Chem::Format#from_filename
). Raises ArgumentError
if the
file format cannot be determined.
The supported file formats are the following:
Chem::Gen
(.gen)Chem::JDFTx
(.ionpos, .lattice)Chem::Mol
(.mol)Chem::Mol2
(.mol2)Chem::PDB
(.ent, .pdb)Chem::PyMOL
(.pml)Chem::SDF
(.sdf)Chem::VMD
(.vmd)Chem::XYZ
(.xyz)Chem::Protein::Stride
(.stride)Chem::VASP::Poscar
(.poscar, POSCAR, CONTCAR)
Use the #to_*
methods to customize how the object is written
in the corresponding file format if possible.