Skip to content

Commit 1bbe798

Browse files
authored
Updated all necessary files pre-release
1 parent f789334 commit 1bbe798

14 files changed

+255
-179
lines changed

Source/BondSpawner.cpp

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ ABondSpawner::ABondSpawner()
1313

1414
}
1515

16+
/**
17+
* Constructs the atom instances in OxygenSpawner blueprint
18+
* @param Transform The locations (position vectors) at which to spawn the instances (atoms)
19+
*/
20+
void ABondSpawner::OnConstruction(const FTransform& Transform)
21+
{
22+
Super::OnConstruction(Transform);
23+
24+
}
25+
1626
// Called when the game starts or when spawned
1727
void ABondSpawner::BeginPlay()
1828
{
@@ -32,6 +42,8 @@ void ABondSpawner::BeginPlay()
3242
TMap<int32, FString> AtomCoordMap = UToolsFunctionLibrary::AtomIndexAndCoordMap(PDBContent, NumberOfAtoms, AtomOnly);
3343
TMap<FString, FString> ConectMap = UToolsFunctionLibrary::ConectInfo(PDBContent);
3444

45+
//UE_LOG(LogTemp, Warning, TEXT("FinalMap key, value: %s, %s"), *pair.Key, *NewConectRow);
46+
3547
for (const TPair<FString, FString>& Pair : ConectMap)
3648
{
3749
//UE_LOG(LogTemp, Warning, TEXT("ConectMap key, value: %s, %s"), *Pair.Key, *Pair.Value);
@@ -49,12 +61,17 @@ void ABondSpawner::BeginPlay()
4961
{
5062
int32 AtomIndex = FCString::Atoi(*OriginalIndex) - 1;
5163
TArray<FString> ValueAtomCoordinates;
64+
//UE_LOG(LogTemp, Warning, TEXT("BondSpawner: AtomCoordMap[AtomIndex]: %s"), *AtomCoordMap[AtomIndex]);
5265
AtomCoordMap[AtomIndex].ParseIntoArray(ValueAtomCoordinates, DelimSpace, true);
5366

54-
FVector ValueAtomCoordinatesVector = FVector(FCString::Atoi(*ValueAtomCoordinates[0]),
55-
FCString::Atoi(*ValueAtomCoordinates[1]), FCString::Atoi(*ValueAtomCoordinates[2])) - CentroidCoordinate;
67+
FVector ValueAtomCoordinatesVector = FVector(
68+
FCString::Atoi(*ValueAtomCoordinates[0]),
69+
FCString::Atoi(*ValueAtomCoordinates[1]),
70+
FCString::Atoi(*ValueAtomCoordinates[2])) - CentroidCoordinate;
5671

57-
FVector BisectPoint = (KeyAtomCoordinatesVector + ValueAtomCoordinatesVector) / 2 - CentroidCoordinate; // where the bond will spawn
72+
// A bond's spawn point is located in the center of the bond cylinder.
73+
// Naturally, it follows that the bond should spawn in the bisect point between the 2 atoms.
74+
FVector BisectPoint = (KeyAtomCoordinatesVector + ValueAtomCoordinatesVector) / 2 - CentroidCoordinate;
5875

5976
// Choose the value atom as the position that the top of the bond will align to, and subtract to align to center
6077
FVector VACVAlign = ValueAtomCoordinatesVector - BisectPoint;
@@ -68,12 +85,50 @@ void ABondSpawner::BeginPlay()
6885

6986
// Angle between the 2 vectors - for determining magnitude of rotation
7087
double Angle = FMath::Acos(FVector::DotProduct(VACVAlignN, StartingVectorN));
88+
double CosAngle = FMath::Cos(Angle);
89+
double SinAngle = FMath::Sin(Angle);
7190

7291
// Find rotation matrix to align StartingVector to VACVAlign - Using Rodrigues rotation method
73-
FMatrix I4 = FMatrix::Identity;
74-
FMatrix I3 = I4.RemoveTranslation();
92+
FMatrix I4 = FMatrix::Identity; // 4 dimensional, remove translation to become 3D
93+
FMatrix I3 = I4.RemoveTranslation(); // 3D identity matrix - [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
94+
95+
/*K.M[0][0] = 0;
96+
K.M[0][1] = -StartingVectorN.Z;
97+
K.M[0][2] = StartingVectorN.Y;
98+
99+
K.M[1][0] = StartingVectorN.Z;
100+
K.M[1][1] = 0;
101+
K.M[1][2] = -StartingVectorN.X;
102+
103+
K.M[2][0] = -StartingVectorN.Y;
104+
K.M[2][1] = StartingVectorN.X;
105+
K.M[2][2] = 0;*/
106+
107+
// Cross-product matrix K
108+
FMatrix K(
109+
FPlane(0.0f, -Axis.Z, Axis.Y, 0.0f),
110+
FPlane(Axis.Z, 0.0f, -Axis.X, 0.0f),
111+
FPlane(-Axis.Y, Axis.X, 0.0f, 0.0f),
112+
FPlane(0.0f, 0.0f, 0.0f, 1.0f)
113+
);
114+
115+
// Rodrigues Rotation Matrix Formula
116+
FMatrix RotationMatrix = I3 +
117+
K * SinAngle +
118+
(K * K) * (1.0f - CosAngle);
119+
75120
}
76-
}
121+
}
122+
123+
// Spawn all bonds
124+
// Should be a bond list
125+
// Or I could generate the instances as I go along
126+
// InstancedStaticMeshComponentBond->AddInstances()
127+
//
128+
// the transform is simply the coordinates of where the cylinder should be placed.
129+
// InstancedStaticMeshComponentBond->AddInstance(TransformObject)
130+
131+
77132
}
78133

79134
// Called every frame

Source/BondSpawner.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class PMUEDEVELOPMENTTWO_API ABondSpawner : public AActor
1515
// Sets default values for this actor's properties
1616
ABondSpawner();
1717

18+
virtual void OnConstruction(const FTransform& Transform) override;
19+
1820
protected:
1921
// Called when the game starts or when spawned
2022
virtual void BeginPlay() override;

Source/CarbonSpawner.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Fill out your copyright notice in the Description page of Project Settings.
22

3+
34
#include "CarbonSpawner.h"
45
#include "ToolsFunctionLibrary.h"
56
#include "FileData.h"
@@ -33,18 +34,22 @@ void ACarbonSpawner::BeginPlay()
3334
{
3435
Super::BeginPlay();
3536

36-
// file-specific variables
37+
// file-specific variables - should be kept in a separate file called by all atom spawner Actors
3738
FileData FD;
3839
FString PDBContent = FD.PDBContent;
3940
FVector CentroidCoordinate = FD.CentroidCoordinate;
41+
bool AtomOnly = FD.AtomOnly;
4042

4143
// variables specific to this spawner
4244
FString CurrentElement{ "C " };
43-
int32 NumberOfAtoms = UToolsFunctionLibrary::NumberOfAtomsSingleElement(PDBContent, CurrentElement, false);
45+
int32 NumberOfAtoms = UToolsFunctionLibrary::NumberOfAtomsSingleElement(PDBContent, CurrentElement, AtomOnly);
46+
UE_LOG(LogTemp, Warning, TEXT("CarbonSpawner: NumberOfAtoms: %d"), NumberOfAtoms);
47+
48+
TArray<int32> CarbonSerials = UToolsFunctionLibrary::ElementIndices(PDBContent, CurrentElement, AtomOnly);
4449
TransformsCarbon.Empty(NumberOfAtoms);
4550

46-
// generates data array of carbons to be spawned
47-
UToolsFunctionLibrary::CCESAtomGeneration(PDBContent, TransformsCarbon, CentroidCoordinate, CurrentElement, false);
51+
// generates data array of atoms to be spawned
52+
UToolsFunctionLibrary::CCESAtomGeneration(PDBContent, TransformsCarbon, CentroidCoordinate, CurrentElement, AtomOnly);
4853

4954
// spawns the actual static mesh
5055
InstancedStaticMeshComponentCarbon->AddInstances(TransformsCarbon, true);

Source/CarbonSpawner.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class PMUEDEVELOPMENTTWO_API ACarbonSpawner : public AActor
1515
// Sets default values for this actor's properties
1616
ACarbonSpawner();
1717

18+
virtual void OnConstruction(const FTransform& Transform) override;
19+
1820
protected:
1921
// Called when the game starts or when spawned
2022
virtual void BeginPlay() override;
@@ -23,8 +25,8 @@ class PMUEDEVELOPMENTTWO_API ACarbonSpawner : public AActor
2325
// Called every frame
2426
virtual void Tick(float DeltaTime) override;
2527

26-
UPROPERTY(Transient)
27-
TArray<FTransform> Transforms;
28+
UPROPERTY(VisibleAnywhere)
29+
TArray<FTransform> TransformsCarbon;
2830

2931
private:
3032
UPROPERTY(VisibleAnywhere)

Source/FileData.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Fill out your copyright notice in the Description page of Project Settings.
2+
3+
4+
#include "FileData.h"
5+
6+
FileData::FileData()
7+
{
8+
}
9+
10+
FileData::~FileData()
11+
{
12+
}

Source/FileData.h

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1-
#pragma once
2-
3-
#include "CoreMinimal.h"
4-
#include "ToolsFunctionLibrary.h"
5-
6-
/**
7-
* FileData class: Contains relevant data from the current PDB file
8-
*/
9-
class PMUEDEVELOPMENTTWO_API FileData
10-
{
11-
public:
12-
FileData();
13-
~FileData();
14-
15-
// All radii have been scaled down by multiplying 0.2/1.7
16-
bool AtomOnly{ false };
17-
FString FileName{ "6a5j-small.pdb" }; //6A5J is a small peptide, I shortened it to Ile-Lys-Lys
18-
FString PDBContent = UToolsFunctionLibrary::ConvFileToString(FileName); // The FString of the PDB file's contents
19-
FVector CentroidCoordinate = UToolsFunctionLibrary::Centroid(PDBContent, AtomOnly); // The coordinates of the centroid
20-
int32 NAtoms = UToolsFunctionLibrary::NumberOfAtoms(PDBContent, AtomOnly); // Number of atoms in the PDB
21-
TMap<int32, FString> IndexAndCoord = UToolsFunctionLibrary::AtomIndexAndCoordMap(PDBContent, NAtoms, AtomOnly);
22-
TMap<FString, FString> BondInfo = UToolsFunctionLibrary::ConectInfo(PDBContent);
23-
int32 SpreadOutFactor{ 1 };
24-
};
1+
// Fill out your copyright notice in the Description page of Project Settings.
2+
3+
#pragma once
4+
5+
#include "CoreMinimal.h"
6+
#include "ToolsFunctionLibrary.h"
7+
8+
/**
9+
* FileData class: Contains relevant data from the current PDB file
10+
*/
11+
class PMUEDEVELOPMENTTWO_API FileData
12+
{
13+
public:
14+
FileData();
15+
~FileData();
16+
17+
// All radii have been scaled down by multiplying 0.2/1.7
18+
bool AtomOnly{ false };
19+
FString FileName{ "6a5j-small.pdb" }; //6A5J is a small peptide, I shortened it to Ile-Lys-Lys
20+
FString PDBContent = UToolsFunctionLibrary::ConvFileToString(FileName); // The FString of the PDB file's contents
21+
FVector CentroidCoordinate = UToolsFunctionLibrary::Centroid(PDBContent, AtomOnly); // The coordinates of the centroid
22+
int32 NAtoms = UToolsFunctionLibrary::NumberOfAtoms(PDBContent, AtomOnly); // Number of atoms in the PDB
23+
TMap<int32, FString> IndexAndCoord = UToolsFunctionLibrary::AtomIndexAndCoordMap(PDBContent, NAtoms, AtomOnly);
24+
TMap<FString, FString> BondInfo = UToolsFunctionLibrary::ConectInfo(PDBContent);
25+
int32 SpreadOutFactor{ 1 };
26+
bool bDebug{ false };
27+
};

Source/HydrogenSpawner.cpp

Lines changed: 65 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,65 @@
1-
#include "HydrogenSpawner.h"
2-
#include "ToolsFunctionLibrary.h"
3-
#include "FileData.h"
4-
5-
// Sets default values
6-
AHydrogenSpawner::AHydrogenSpawner()
7-
{
8-
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
9-
PrimaryActorTick.bCanEverTick = false;
10-
InstancedStaticMeshComponentHydrogen = CreateDefaultSubobject<UInstancedStaticMeshComponent>(TEXT("Instanced Static Mesh"));
11-
12-
//RootComponent = InstancedStaticMeshComponentHydrogen;
13-
14-
InstancedStaticMeshComponentHydrogen->SetMobility(EComponentMobility::Movable);
15-
InstancedStaticMeshComponentHydrogen->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
16-
InstancedStaticMeshComponentHydrogen->SetGenerateOverlapEvents(false);
17-
}
18-
19-
/**
20-
* Constructs the atom instances in HydrogenSpawner blueprint
21-
* @param Transform The locations (position vectors) at which to spawn the instances (atoms)
22-
*/
23-
void AHydrogenSpawner::OnConstruction(const FTransform& Transform)
24-
{
25-
Super::OnConstruction(Transform);
26-
27-
}
28-
29-
// Called when the game starts or when spawned
30-
void AHydrogenSpawner::BeginPlay()
31-
{
32-
Super::BeginPlay();
33-
34-
// file-specific variables
35-
FileData FD;
36-
FString PDBContent = FD.PDBContent;
37-
FVector CentroidCoordinate = FD.CentroidCoordinate;
38-
39-
// variables specific to this spawner
40-
FString CurrentElement{ "H " };
41-
int32 NumberOfAtoms = UToolsFunctionLibrary::NumberOfAtomsSingleElement(PDBContent, CurrentElement, false);
42-
TransformsHydrogen.Empty(NumberOfAtoms);
43-
44-
// generates data array of atoms to be spawned
45-
UToolsFunctionLibrary::CCESAtomGeneration(PDBContent, TransformsHydrogen, CentroidCoordinate, CurrentElement, false);
46-
47-
// spawns the actual static mesh
48-
InstancedStaticMeshComponentHydrogen->AddInstances(TransformsHydrogen, true);
49-
50-
}
51-
52-
// Called every frame
53-
void AHydrogenSpawner::Tick(float DeltaTime)
54-
{
55-
Super::Tick(DeltaTime);
56-
57-
}
58-
1+
// Fill out your copyright notice in the Description page of Project Settings.
2+
3+
4+
#include "HydrogenSpawner.h"
5+
#include "ToolsFunctionLibrary.h"
6+
#include "FileData.h"
7+
8+
// Sets default values
9+
AHydrogenSpawner::AHydrogenSpawner()
10+
{
11+
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
12+
PrimaryActorTick.bCanEverTick = false;
13+
InstancedStaticMeshComponentHydrogen = CreateDefaultSubobject<UInstancedStaticMeshComponent>(TEXT("Instanced Static Mesh"));
14+
15+
//RootComponent = InstancedStaticMeshComponentHydrogen;
16+
17+
InstancedStaticMeshComponentHydrogen->SetMobility(EComponentMobility::Movable);
18+
InstancedStaticMeshComponentHydrogen->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
19+
InstancedStaticMeshComponentHydrogen->SetGenerateOverlapEvents(false);
20+
}
21+
22+
/**
23+
* Constructs the atom instances in HydrogenSpawner blueprint
24+
* @param Transform The locations (position vectors) at which to spawn the instances (atoms)
25+
*/
26+
void AHydrogenSpawner::OnConstruction(const FTransform& Transform)
27+
{
28+
Super::OnConstruction(Transform);
29+
30+
}
31+
32+
// Called when the game starts or when spawned
33+
void AHydrogenSpawner::BeginPlay()
34+
{
35+
Super::BeginPlay();
36+
37+
// file-specific variables
38+
FileData FD;
39+
FString PDBContent = FD.PDBContent;
40+
FVector CentroidCoordinate = FD.CentroidCoordinate;
41+
bool AtomOnly = FD.AtomOnly;
42+
TMap<FString, FString> BondInfo = FD.BondInfo;
43+
44+
// variables specific to this spawner
45+
FString CurrentElement{ "H " };
46+
int32 NumberOfAtoms = UToolsFunctionLibrary::NumberOfAtomsSingleElement(PDBContent, CurrentElement, AtomOnly);
47+
TransformsHydrogen.Empty(NumberOfAtoms);
48+
49+
// generates data array of atoms to be spawned
50+
UToolsFunctionLibrary::CCESAtomGeneration(PDBContent, TransformsHydrogen, CentroidCoordinate, CurrentElement, AtomOnly);
51+
52+
// spawns the actual static mesh
53+
InstancedStaticMeshComponentHydrogen->AddInstances(TransformsHydrogen, true);
54+
55+
// debugging
56+
//UToolsFunctionLibrary::ConectInfo(PDBContent);
57+
}
58+
59+
// Called every frame
60+
void AHydrogenSpawner::Tick(float DeltaTime)
61+
{
62+
Super::Tick(DeltaTime);
63+
64+
}
65+

0 commit comments

Comments
 (0)