class Chem::Structure

Overview

Gather, check and annotate types registering a format

Defined in:

chem/core/structure.cr
chem/register_format.cr

Constant Summary

MAX_CHAINS = 62
MIN_RING_ANGLE = 50

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.build(*args, **options, &) : self #

[View source]
def self.from_chgcar(io : IO) : self #

[View source]
def self.from_chgcar(path : Path | String) : self #

[View source]
def self.from_cube(io : IO) : self #

[View source]
def self.from_cube(path : Path | String) : self #

[View source]
def self.from_gen(io : IO, guess_bonds : Bool = false, guess_names : Bool = false) : self #

[View source]
def self.from_gen(path : Path | String, guess_bonds : Bool = false, guess_names : Bool = false) : self #

[View source]
def self.from_jdftx(io : IO, guess_bonds : Bool = false, guess_names : Bool = false) : self #

[View source]
def self.from_jdftx(path : Path | String, guess_bonds : Bool = false, guess_names : Bool = false) : self #

[View source]
def self.from_locpot(io : IO) : self #

[View source]
def self.from_locpot(path : Path | String) : self #

[View source]
def self.from_mol(io : IO) : self #

[View source]
def self.from_mol(path : Path | String) : self #

[View source]
def self.from_mol2(io : IO) : self #

[View source]
def self.from_mol2(path : Path | String) : self #

[View source]
def self.from_pdb(io : IO, info : PDB::Info | Nil = nil, alt_loc : Char | Nil = nil, chains : Enumerable(Char) | String | Nil = nil, guess_bonds : Bool = false, het : Bool = true) : self #

[View source]
def self.from_pdb(path : Path | String, info : PDB::Info | Nil = nil, alt_loc : Char | Nil = nil, chains : Enumerable(Char) | String | Nil = nil, guess_bonds : Bool = false, het : Bool = true) : self #

[View source]
def self.from_poscar(io : IO, guess_bonds : Bool = false, guess_names : Bool = false) : self #

[View source]
def self.from_poscar(path : Path | String, guess_bonds : Bool = false, guess_names : Bool = false) : self #

[View source]
def self.from_psf(io : IO) : self #

[View source]
def self.from_psf(path : Path | String) : self #

[View source]
def self.from_sdf(io : IO) : self #

[View source]
def self.from_sdf(path : Path | String) : self #

[View source]
def self.from_xyz(io : IO, guess_bonds : Bool = false, guess_names : Bool = false) : self #

[View source]
def self.from_xyz(path : Path | String, guess_bonds : Bool = false, guess_names : Bool = false) : self #

[View source]
def self.new(source_file : Path | String | Nil = nil) #

[View source]
def self.read(input : IO | Path | String, format : Chem::Cube.class) : self #

[View source]
def self.read(input : IO | Path | String, format : Chem::Gen.class) : self #

[View source]
def self.read(input : IO | Path | String, format : Chem::JDFTx.class) : self #

[View source]
def self.read(input : IO | Path | String, format : Chem::Mol.class) : self #

[View source]
def self.read(input : IO | Path | String, format : Chem::Mol2.class) : self #

[View source]
def self.read(input : IO | Path | String, format : Chem::PDB.class) : self #

[View source]
def self.read(input : IO | Path | String, format : Chem::PSF.class) : self #

[View source]
def self.read(input : IO | Path | String, format : Chem::SDF.class) : self #

[View source]
def self.read(input : IO | Path | String, format : Chem::XYZ.class) : self #

[View source]
def self.read(input : IO | Path | String, format : Chem::VASP::Chgcar.class) : self #

[View source]
def self.read(input : IO | Path | String, format : Chem::VASP::Locpot.class) : self #

[View source]
def self.read(input : IO | Path | String, format : Chem::VASP::Poscar.class) : self #

[View source]
def self.read(input : IO | Path | String, format) : self #

FIXME Make it compile time error. Should raise if format is not registered or format is incompatible with open_type. Better create an override with the other formats, and leave this as a fallback.


[View source]
def self.read(path : IO | Path | String) : self #

[View source]

Class Method Detail

def self.guess_element(atom_name : String) : Element #

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


[View source]
def self.guess_element?(atom_name : String) : Element | Nil #

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


[View source]

Instance Method Detail

def [](chain_id : Char) : Chain #

[View source]
def []?(chain_id : Char) : Chain | Nil #

[View source]
def angles : Array::View(Angle) #

Returns the angles in the topology. See Angle for definition.


[View source]
def angles=(angles : Array(Chem::Angle)) #

Angles in the topology. See Angle for definition.


[View source]
def apply_templates : Nil #

Assign bonds, formal charges, and residue's type from known residue types.


[View source]
def atoms : AtomView #

[View source]
def biases : Array(Chem::Bias) #

[View source]
def bonds : Array(Bond) #

Returns the bonds between all atoms.


[View source]

Returns the unit cell. Raises Spatial::NotPeriodicError if cell is nil.


[View source]
def cell=(cell : Spatial::Parallelepiped | Nil) #

[View source]
def cell? : Spatial::Parallelepiped | Nil | Nil #

[View source]
def chains : ChainView #

[View source]
def clear : self #

[View source]
def clone : self #

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

[View source]
def delete(ch : Chain) : Chain | Nil #

[View source]
def dig(id : Char) : Chain #

[View source]
def dig(id : Char, *subindexes) #

[View source]
def dig?(id : Char) : Chain | Nil #

[View source]
def dig?(id : Char, *subindexes) #

[View source]
def dihedrals : Array::View(Dihedral) #

Returns the dihedral angles in the topology. See Dihedral for definition.


[View source]
def dihedrals=(dihedrals : Array(Chem::Dihedral)) #

Dihedral angles in the topology. See Dihedral for definition.


[View source]
def experiment : Structure::Experiment | Nil #

[View source]
def experiment=(experiment : Structure::Experiment | Nil) #

[View source]
def extract(copy_properties : Bool = true, & : Atom -> Bool) : self #

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.


[View source]
def formal_charge : Int32 #

TODO implement compound accessors in a global module


[View source]
def guess_angles : Nil #

Determines the angles based on connectivity. See Angle for definition.

NOTE It deletes existing angles.


[View source]
def guess_bonds(perceive_order : Bool = true) : Nil #

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.


[View source]
def guess_dihedrals : Nil #

Determines the dihedral angles based on connectivity. See Dihedral for definition.

NOTE It deletes existing dihedral angles.


[View source]
def guess_formal_charges : Nil #

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.


[View source]
def guess_impropers : Nil #

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.


[View source]
def guess_names(registry : Templates::Registry = Templates::Registry.default) : Nil #

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.


[View source]
def guess_unknown_residue_types : Nil #

Determines the type of unknown residues based on their neighbors.


[View source]
def impropers : Array::View(Improper) #

Returns the improper dihedral angles in the topology. See Improper for definition.


[View source]
def impropers=(impropers : Array(Chem::Improper)) #

Improper dihedral angles in the topology. See Improper for definition.


[View source]
def inspect(io : IO) : Nil #
Description copied from class Reference

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>

[View source]
def metadata : Chem::Metadata #

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

[View source]
def periodic? : Bool #

[View source]

[View source]

Sets the atom coordinates and cell.


[View source]

Sets the atom coordinates.


[View source]
def renumber_residues_by(& : Residue -> _) : Nil #

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.


[View source]
def renumber_residues_by_connectivity(split_chains : Bool = true) : Nil #

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.


[View source]
def reset_connectivity : Nil #

Deletes all bonds and resets formal charges to zero.


[View source]
def residues : ResidueView #

[View source]
def source_file : Path | Nil #

[View source]
def title : String #

[View source]
def title=(title : String) #

[View source]
def to_gen(io : IO, fractional : Bool = false) : Nil #

[View source]
def to_gen(fractional : Bool = false) : String #

[View source]
def to_gen(path : Path | String, fractional : Bool = false) : Nil #

[View source]
def to_jdftx(io : IO, fractional : Bool = false, wrap : Bool = false, single_file : Bool = true) : Nil #

[View source]
def to_jdftx(fractional : Bool = false, wrap : Bool = false, single_file : Bool = true) : String #

[View source]
def to_jdftx(path : Path | String, fractional : Bool = false, wrap : Bool = false, single_file : Bool = true) : Nil #

[View source]
def to_mol(io : IO, variant : Mol::Variant = :v2000) : Nil #

[View source]
def to_mol(variant : Mol::Variant = :v2000) : String #

[View source]
def to_mol(path : Path | String, variant : Mol::Variant = :v2000) : Nil #

[View source]
def to_mol2(io : IO) : Nil #

[View source]
def to_mol2(path : Path | String) : Nil #

[View source]
def to_mol2 : String #

[View source]
def to_pdb(io : IO, conect conect_options : PDB::ConectOptions = PDB::ConectOptions.flags(Het, Disulfide), renumber : Bool = true, ter_on_fragment : Bool = false, include_header : Bool = true, include_end : Bool = true) : Nil #

[View source]
def to_pdb(conect conect_options : PDB::ConectOptions = PDB::ConectOptions.flags(Het, Disulfide), renumber : Bool = true, ter_on_fragment : Bool = false, include_header : Bool = true, include_end : Bool = true) : String #

[View source]
def to_pdb(path : Path | String, conect conect_options : PDB::ConectOptions = PDB::ConectOptions.flags(Het, Disulfide), renumber : Bool = true, ter_on_fragment : Bool = false, include_header : Bool = true, include_end : Bool = true) : Nil #

[View source]
def to_poscar(io : IO, order : Array(Element) | Array(String) | Nil = nil, fractional : Bool = false, wrap : Bool = false) : Nil #

[View source]
def to_poscar(order : Array(Element) | Array(String) | Nil = nil, fractional : Bool = false, wrap : Bool = false) : String #

[View source]
def to_poscar(path : Path | String, order : Array(Element) | Array(String) | Nil = nil, fractional : Bool = false, wrap : Bool = false) : Nil #

[View source]
def to_poscar(order : Array(Element) | Array(String) | Nil = nil, fractional : Bool = false, wrap : Bool = false) : String #

[View source]
def to_pymol(io : IO) : Nil #

[View source]
def to_pymol(path : Path | String) : Nil #

[View source]
def to_pymol : String #

[View source]
def to_s(io : IO) #
Description copied from class Reference

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>

[View source]
def to_sdf(io : IO, variant : Mol::Variant = :v2000) : Nil #

[View source]
def to_sdf(variant : Mol::Variant = :v2000) : String #

[View source]
def to_sdf(path : Path | String, variant : Mol::Variant = :v2000) : Nil #

[View source]
def to_stride(io : IO) : Nil #

[View source]
def to_stride(path : Path | String) : Nil #

[View source]
def to_stride : String #

[View source]
def to_vmd(io : IO) : Nil #

[View source]
def to_vmd(path : Path | String) : Nil #

[View source]
def to_vmd : String #

[View source]
def to_xyz(io : IO, extended : Bool = false, fields : Array(String) = [] of String) : Nil #

[View source]
def to_xyz(extended : Bool = false, fields : Array(String) = [] of String) : String #

[View source]
def to_xyz(path : Path | String, extended : Bool = false, fields : Array(String) = [] of String) : Nil #

[View source]
def write(output : IO | Path | String, format : Chem::Gen.class) : Nil #

[View source]
def write(output : IO | Path | String, format : Chem::JDFTx.class) : Nil #

[View source]
def write(output : IO | Path | String, format : Chem::Mol.class) : Nil #

[View source]
def write(output : IO | Path | String, format : Chem::Mol2.class) : Nil #

[View source]
def write(output : IO | Path | String, format : Chem::PDB.class) : Nil #

[View source]
def write(output : IO | Path | String, format : Chem::PyMOL.class) : Nil #

[View source]
def write(output : IO | Path | String, format : Chem::SDF.class) : Nil #

[View source]
def write(output : IO | Path | String, format : Chem::VMD.class) : Nil #

[View source]
def write(output : IO | Path | String, format : Chem::XYZ.class) : Nil #

[View source]
def write(output : IO | Path | String, format : Chem::Protein::Stride.class) : Nil #

[View source]
def write(output : IO | Path | String, format : Chem::VASP::Poscar.class) : Nil #

[View source]
def write(output : IO | Path | String, format) : Nil #

FIXME Make it compile time error. Should raise if format is not registered or format is incompatible with open_type. Better create an override with the other formats, and leave this as a fallback.


[View source]
def write(path : IO | Path | String) : Nil #

[View source]